Skip to content

Instantly share code, notes, and snippets.

@aegrumet
Last active December 21, 2015 22:19
Show Gist options
  • Save aegrumet/6374367 to your computer and use it in GitHub Desktop.
Save aegrumet/6374367 to your computer and use it in GitHub Desktop.
AWS command-line jq commands
# ec2 instance info
aws ec2 describe-instances | sed -e 's/"Key"/"key"/' -e 's/"Value"/"value"/' |jq -c '[.Reservations[].Instances[]|{PrivateIpAddress,PublicIpAddress, AZ: .Placement.AvailabilityZone, Name: (.Tags|from_entries|.Name)}]|sort_by(.Name)[]'
# ec2 instance info with filter
aws --profile us ec2 describe-instances --filters '[{"Name":"tag-key","Values":["Name"]}, {"Name":"tag-value","Values":["*agentserver*"]}]' | sed -e 's/"Key"/"key"/' -e 's/"Value"/"value"/' |jq -c '[.Reservations[].Instances[]|{PrivateIpAddress,PublicIpAddress, AZ: .Placement.AvailabilityZone, Name: (.Tags|from_entries|.Name)}]|sort_by(.Name)[]'
# ebs snapshot info
snapName="mysnapshot"; aws ec2 describe-snapshots --filter '{"name":"tag-key","values":"Name"}' --filter "{\"name\":\"tag-value\",\"values\":\"$snapName\"}" | jq -c '[.Snapshots[]|{VolumeId, SnapshotId, Description, StartTime}]|sort_by(.StartTime)[]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment