ImageId requried when launching instance via a Launch Template

0

The documentation (https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#runinstances) claims that I can either specify ImageId directly or via a launch template. But if I specify it in a launch template, the request fails validation. The SDK doesn't even make an outbound connection, just errors out immediately.

How can I make EC2 use the ImageId specified in my launch template?

I'm using the following code to launch an EC2 instance using a launch template:

        $result = $ec2->runInstances([
            'DryRun' => false,
            'LaunchTemplate' => [
                'LaunchTemplateName' => 'test-template',
                'Version' => 1
            ],
            'MinCount' => 1,
            'MaxCount' => 1
        ]);

The template ("test-template" Version 1) has an AMI specified (ami-086b3de06dafe36c5 - Amazon Linux 2). When I run the code above, I immediatelly get the following:

Found 1 error while validating the input provided for the RunInstances operation: [ImageId] is missing and is a required parameter 
gefragt vor einem Jahr310 Aufrufe
1 Antwort
0

I resolved the issue, for some reason "composer require aws/aws-sdk-php" installed an ancient version of the SDK

beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen