I've specified an EC2 instance in my CloudFormation template, and I want to tag it with it's own InstanceId, like so:
"Resources": {
"myInstance": {
...
"Tags": [
{ "Key": "instance.id", "Value": { "Ref": "myInstance" } },
...
]
}
}
But trying to create a stack from this template generates a AmazonCloudFormationException
: "Circular dependency between resources: [myInstance]"
Running instances and tagging them using the EC2 API is very straightforward:
//this is C#, but that's not significant
var instance = ec2Client.RunInstances(...) ...;
var id = instance.InstanceId;
ec2Client.CreateTags(new CreateTagRequest
{
Resources = { id },
Tags = { new Tag { Key = "instance.id", Value = id } }
});
This approach arises naturally from the fact that instance tags cannot be created as part of the RunInstances
operation, so all tags, not just the self-identifier, must be applied in a subsequent API operation.
So... can I accomplish the same thing using CloudFormation? Thanks very much!