I am trying to create an instance in ec2 using CLI. Is there anyway to specify tags to the instance when using CLI to create instances?

aws ec2 run-instances --image-id $ami_id --key-name $deployment_key_name \
--region $region --security-groups default --instance-type m4.large \
--user-data file://./yaml/master.yaml

2 Answers 2


As of 28 March 2017, you can specify tags for instances (and attached volumes) as part of the run-instances command.


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=cost-center,Value=cc123}]' 

Announcement blog post: https://aws.amazon.com/blogs/aws/new-tag-ec2-instances-ebs-volumes-on-creation/

Additional documentation (see example 4): http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#Using_Tags_CLI

  • 1
    just a small add - you need to upgrade or reinstall your AWS EC2 Cli
    – Up_One
    Nov 11, 2017 at 0:38

Use the aws ec2 create-tags command afterwards to add tags by instance ID.

  • I need to add tags when creating instances, like from GUI Sep 24, 2015 at 9:37
  • There's no way to do it in a single command. You must use this second command after the instance is launched. The GUI does the same thing but it hides it. Sep 25, 2015 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.