Skip to content

Instantly share code, notes, and snippets.

@noahehall
Forked from avital-tamir/awscli-cookbook
Created May 12, 2016 14:06
Show Gist options
  • Save noahehall/1ef4117f61526b7f2e12af80b72fdb4a to your computer and use it in GitHub Desktop.
Save noahehall/1ef4117f61526b7f2e12af80b72fdb4a to your computer and use it in GitHub Desktop.
AWS Cookbook
# Get a (filtered) list of AWS instances, comma separated:
#
# Here's the reference to the 'describe-instances' command in aws-cli,
# check out the filters section.
# http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html
$ aws ec2 describe-instances --filters "Name=availability-zone,Values=us*" | \
jq -r '.Reservations[] | .Instances[] | "\(.InstanceId)"' | \
tr '\n' ','
# Example: Create tags on these instances:
$ aws ec2 create-tags --resources `aws ec2 describe-instances --filters "Name=availability-zone,Values=us*" | jq -r '.Reservations[] | .Instances[] | "\(.InstanceId)"' | tr '\n' ' '` --tags "Key=Env,Value=Production"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment