Skip to content

Instantly share code, notes, and snippets.

@ezarko
Created March 19, 2015 19:22
Show Gist options
  • Save ezarko/36e32ecbc07b80b8f2e1 to your computer and use it in GitHub Desktop.
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
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