Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name an EC2 Instance in the CloudFormation template?

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.

like image 977
A.G. Avatar asked Mar 06 '13 23:03

A.G.


People also ask

How do I name an EC2 instance in CloudFormation?

A.G. 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).

How do you name resources in CloudFormation?

Names must begin with a letter; contain only ASCII letters, digits, and hyphens; and not end with a hyphen or contain two consecutive hyphens. Also, don't manage stack resources outside of CloudFormation.

How do I change instance type in CloudFormation?

In order to make a change to an immutable property, AWS CloudFormation must launch a replacement resource, in this case a new Amazon EC2 instance running the new AMI. After the new instance is running, AWS CloudFormation updates the other resources in the stack to point to the new resource.


1 Answers

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" }}         ]     } } 
like image 85
Pete - MSFT Avatar answered Nov 08 '22 08:11

Pete - MSFT