Created
December 11, 2019 13:15
-
-
Save sportebois/6ffbbe58fb7a9808e630ae5393df3a59 to your computer and use it in GitHub Desktop.
Dumps a CSV of EC2 instances (no pagination, up to 200 per region)
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
#!/usr/bin/env bash | |
set -eu | |
dumpInstances() { | |
local readonly region="$1" | |
local readonly date_ts="$(date +%Y%m%d-%H%M)" | |
aws ec2 describe-instances \ | |
--max-items 200 \ | |
--region "$region" \ | |
--page-size 200 \ | |
--query 'Reservations[*].Instances[*].[InstanceId,InstanceType,Placement.AvailabilityZone,Tags[?Key==`Name`].Value,Tags[?Key==`Environment`].Value]' \ | |
| jq -r '.[] | .[] | {"id": .[0], "type": .[1], "az": .[2] ,"name": .[3][0], "environment": .[4][0]} | [.id, .type, .az, .name, .environment] | @csv' \ | |
| tee /dev/tty > "ec2-inventory-${region}-${date_ts}.csv" | |
} | |
dumpInstances "us-east-1" | |
dumpInstances "eu-central-1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment