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?
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" .
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 :
There should be a space between each Key,Value pair. Like
Key=foo,Value=something<space_here> Key=boo,Value=somethingelse
If we don't add spaces between each pair last pair of Key,Value will be only applied.
You can keep any Value empty too provided we have a Key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With