I am able to successfully launch new instances using AWS SDK for PHP. However, I am not able to add tags ('Name' = 'New Instance'). I tried doing it in several ways, with the following seeming the most reasonable. However, upon refreshing the EC2 dashboard, I can see that the new instance is created, however, the name tag is still blank.
$ec2Client = new Ec2Client([
'region' => 'xx-xxxx-1',
'version' => 'latest',
'profile' => 'default'
]);
// Launch an instance with the key pair and security group
$result = $ec2Client->runInstances(array(
'ImageId' => 'ami-xxxxxxxx',
'MinCount' => 1,
'MaxCount' => 1,
'InstanceType' => 't2.large',
'KeyName' => 'xxxxxx',
'SubnetId' => 'subnet-xxxxxxxx',
'VpcId' => 'vpc-xxxxxxxx',
'Tags' => array(
'Key' => 'Name',
'Value' => 'New Instance',
),
'SecurityGroups'[1] => 'sg-xxxxxxxx',
));
I don't know what version of SDK you are using, but from AWS v2 SDK documentation there is no
Tagskey.Try using other function
createTags. Note thatTagsis double array, not like in your example.