Created
March 19, 2015 19:22
-
-
Save ezarko/36e32ecbc07b80b8f2e1 to your computer and use it in GitHub Desktop.
Add a tag "somekey" with "somevalue" to all EC2 instances that do not have that tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws ec2 create-tags --resources $(perl -MJSON -e '$d=[grep{$_->{State}{Name}eq"running"&&!$_->{Tags}{somekey}}map{map{$_->{Tags}={map{($_->{Key}=>$_->{Value})}@{$_->{Tags}}};$_}@{$_->{Instances}}}@{(decode_json scalar `aws ec2 describe-instances`)->{Reservations}}];print join(" ",map{$_->{InstanceId}}@$d)') --tags Key=somekey,Value=somevalue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment