8

How to give Name in command line when running aws ec2 run-instances ?

I don't find it in the official docs

screenshot

MLu
  • 24,849
  • 5
  • 59
  • 86
user5858
  • 263
  • 1
  • 5
  • 17

2 Answers2

16

The Name that's displayed there is taken from the Name tag. To set the instance name e.g. to test01 and its volume name to test01-disk1 you'd run something like this:

aws ec2 run-instances --tag-specifications \
    'ResourceType=instance,Tags=[{Key=Name,Value=test01}]' \
    'ResourceType=volume,Tags=[{Key=Name,Value=test01-disk1}]' \
    ... other parameters ...

Hope that helps :)

MLu
  • 24,849
  • 5
  • 59
  • 86
1

Install jq

aws ec2 create-tags --resources \
  `aws ec2 run-instances --image-id ami-8f50120g --instance-type t2.small \
  --subnet-id subnet-xxxxxxx --security-group-ids sg-xxxxxxxx --key-name "MyKey" \
  | jq -r ".Instances[0].InstanceId"` \
  --tags "Key=Name,Value=development"
Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
kkashyap1707
  • 111
  • 2