Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we add multiple tags to a AWS resource with one aws cli command?

I am trying to add tags to Ec2 resource using aws cli command with jenkins:-

The command is:

aws ec2 create-tags --resources $instance_id --region $region --tags Key=$Tagkey,Value=$Tagvalue

My question here is that can we add more than one key/value to this resource with one aws cli command or we need to run this command multiple times if I want to add more key/value pairs?

like image 633
gulshan kumar Avatar asked Dec 14 '17 10:12

gulshan kumar


2 Answers

Yes you can add multiple tags using one AWS cli command seperated by space between tags. For ex:

  aws ec2 create-tags --resources $instance_id --region $region  --tags "Key"="owner","Value"="admin" "Key"="environment","Value"="test" "Key"="version","Value"="1.0" .
like image 195
sanath meti Avatar answered Sep 30 '22 17:09

sanath meti


This exact thing works perfectly fine for me.

aws --region eu-central-1 ec2 create-tags --resource $subnet_id \
--tags Key=Region,Value=eu-central-1 Key=Stage,\
Value=Dev Key=Owner,Value=somevaluehere Key=Name,\
Value=dev-Public-3 Key=Type,Value=  Key=Shared,Value=true

There are three things especially to pay attention to :

  1. There should be a space between each Key,Value pair. Like

    Key=foo,Value=something<space_here> Key=boo,Value=somethingelse

  2. If we don't add spaces between each pair last pair of Key,Value will be only applied.

  3. You can keep any Value empty too provided we have a Key.

like image 37
samtoddler Avatar answered Sep 30 '22 19:09

samtoddler