Last active
July 18, 2018 08:42
-
-
Save joerx/4af0238b28521f5f5b6c7db2734f551a to your computer and use it in GitHub Desktop.
AWS CLI and jq fu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Mac, pipe into
pbcopy
to send output to clipboard