Created
July 18, 2018 06:49
-
-
Save niksrc/02c38d849ef26654c4ecf19d2e6c1c2e to your computer and use it in GitHub Desktop.
Get non reserved instances running in EC2
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
reserved=$(aws ec2 describe-reserved-instances | jq '.ReservedInstances | map(select(.State == "active")) | map({ (.InstanceType): .InstanceCount }) | map(to_entries) | add | group_by(.key) | map({key: .[0].key, value: map(.value) | add }) | from_entries') | |
running=$(aws ec2 describe-instances | jq '.Reservations | map(.Instances) | flatten | map(select(.State.Code == 16 and .InstanceLifecycle != "spot")) | map(.InstanceType) | group_by(.) | map({ (.[0]|tostring) : .|length }) | add') | |
echo $reserved, $running |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment