Skip to content

Instantly share code, notes, and snippets.

View paolo-ciuffetti's full-sized avatar

Paolo Ciuffetti paolo-ciuffetti

View GitHub Profile
@paolo-ciuffetti
paolo-ciuffetti / bash_aws_jq_cheatsheet.sh
Last active August 5, 2022 11:48 — forked from lukeplausin/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely, returning InstanceName as 'null' on instances without Tags
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, InstanceName: (if(.Tags) then (.Tags[] | select(.Key == "Name") | .Value) else ("null") end)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account