I have a template that works and generates a stack but I cannot find a property to set or something else that allows me to give a Name to the EC2 Instance I have created. When it is generated the Name is blank.
Asked
Active
Viewed 2.8k times
66
-
My comment is not about templates, but this is the only question I find about naming EC2 instances, so I'm writing this here. You can name an instance by select the instance and choosing Actions => Edit Tags and add a tag for Name (case sensitive). Also, if you hover your mouse over the blank field in the Name column a little pencil icon appears that you can click on that to edit the tag more directly. – Emery Lapinski May 18 '15 at 15:14
1 Answers
105
You need to add a tag with key Name
to the cloud formation template. Like this...
"ec2-instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : "ami-0102022,
"SecurityGroupIds" : [{ "Ref" : "SecurityGroup" }],
"SubnetId" : { "Ref" : "Subnet" },
"InstanceType" : "m1.medium",
"Tags" : [
{"Key" : "Name", "Value" : "Instance name"},
{"Key" : "Environment", "Value" : { "Ref" : "Environment" }},
{"Key" : "Owner", "Value" : { "Ref" : "Owner" }}
]
}
}

David Jones
- 4,766
- 3
- 32
- 45

Pete - MSFT
- 4,249
- 1
- 21
- 38
-
11Note that if you use autoscaling group, the tags need to be added in the Autoscaling group properties and the property `PropagateAtLaunch` should be set to `true`. – WispyCloud Sep 16 '13 at 01:08
-
@jtblin can you give some guidance on what you mean? I'm looking for more info on the PropogateAtLuanch and why it needs to be set true. – John Smith Jan 10 '14 at 22:17
-
6@JohnSmith Just google it, first result is http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-tags.html. > `PropagateAtLaunch`: Set to true if you want AWS CloudFormation to copy the tag to EC2 instances that are launched as part of the auto scaling group. Set to false if you want the tag attached only to the auto scaling group and not copied to any instances launched as part of the auto scaling group. Required: Yes. Type: Boolean. < Basically if you have an autoscaling group and want the tag to be added to the instances, you need to set this property to `true`. – WispyCloud Jan 11 '14 at 04:07
-
2Thanks @jtblin. I think my confusion was where and how to use the property. I read through the docs and found an example that shows Its not just a key value pair. The PropagateAtLaunch is the third value in the set. {"Key" : "Name", "Value" : "Instance name", "PropagateAtLaunch" : true}. Also worth noting that I didn't have to add any tags to the ec2-instance block. Everything was set in the Autoscaling group – John Smith Jan 13 '14 at 23:56
-
@Pete could you give a pointer to where in the CloudFormation documentation this information is? I mean it works (thanks!) but I'm frustrated that I cannot find this info in the official documentation – Cédric Van Rompay Nov 12 '19 at 15:34
-
It wasn't at the time. I worked it out via trial and error. (and wow - this is an old answer!!) – Pete - MSFT Nov 13 '19 at 10:51