mspices
mspices

Reputation: 459

How to set instance name from cli

When logged in to the AWS EC2 Management Console, the list of instances has, as its first column, "Name" (followed by "Instance ID", etc).

For instances created through AWS CLI (using aws ec2 run-instances), the name field is empty. How can I set the name programmatically?

Also, is there any implication for giving it a name (e.g. does it have to be unique, and is the name used by something?) I would like to have it as a useful info, for managing my instances from the console.

Upvotes: 2

Views: 2534

Answers (1)

Dennis Traub
Dennis Traub

Reputation: 51674

By convention, the name that's displayed in the instance list is a resource tag with the Key Name and the name of your choice as its value.

You can do this via the AWS CLI using the --tag-specifications option as documented here:

aws ec2 run-instances [other options] --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=MyInstanceName}]'

Alternatively, you can also add tags, including the Name tag to existing resources using aws ec2 create-tag.

Upvotes: 7

Related Questions