Skip to content

Instantly share code, notes, and snippets.

@joerx
Last active July 18, 2018 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerx/4af0238b28521f5f5b6c7db2734f551a to your computer and use it in GitHub Desktop.
Save joerx/4af0238b28521f5f5b6c7db2734f551a to your computer and use it in GitHub Desktop.
AWS CLI and jq fu
# Using AWS CLI with jq can be a very powerful tool to collect various reports from your AWS account.
# With the `@tsv` filter we can write TSV output for easy copy & pasting into our favourite spreadsheet app
# Use `@csv` to get a CSV output instead
# List VPCs with names
aws ec2 describe-vpcs | jq -r '.Vpcs[]|[.VpcId,(.Tags|map(select(.Key=="Name"))[0].Value)]|@tsv'
# List EC2 instances with selected attributes
aws ec2 describe-instances | jq -r '.Reservations[].Instances[]|[.InstanceId,.InstanceType,.State.Name,.VpcId,(.Tags|map(select(.Key=="Name"))[0].Value)]|@tsv'
# Kubectl is another candidate that produces JSON output consumable by jq:
# List of nodes and role:
kubectl get node -o json | jq -r '.items[] | [.metadata.labels["kubernetes.io/role"],.metadata.name] | @tsv'
@joerx
Copy link
Author

joerx commented Jul 18, 2018

On Mac, pipe into pbcopy to send output to clipboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment