mspices
mspices

Reputation: 459

How to set volume name from cli

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

For instances created through AWS CLI (using aws ec2 run-instances), a volume gets created automatically, and the corresponding 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 volumes from the console.

Upvotes: 1

Views: 1111

Answers (1)

saurabh14292
saurabh14292

Reputation: 1401

"Name" is just a Tag. A key. You can specify it as below :

aws ec2 run-instances \
    --image-id ami-abc12345 \
    --count 1 \
    --instance-type t2.micro \
    --key-name MyKeyPair \
    --subnet-id subnet-6e7f829e \
    --tag-specifications 'ResourceType=instance,Tags=[{Key=webserver,Value=production}]' 'ResourceType=volume,Tags=[{Key=Name,Value=cc123}]'

This will create required EC2 instance and default EBS volume with tag "Name" which has value of "cc123".

Reference : https://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html

You can launch an instance and specify tags for the instance, volumes, or both. The following example applies a tag with a key of webserver and value of production to the instance. The command also applies a tag with a key of cost-center and a value of cc123 to any EBS volume that's created (in this case, the root volume).

Regarding implications, you can have any value to the key. It is not required to be unique. However, what you have to note is that, the tags (Key-Value pairs) should reflect the real-world as to identify the resources.

Upvotes: 3

Related Questions