Created
June 13, 2022 07:58
-
-
Save pjoe/333736a5d3d64cd0be869bf7451ad522 to your computer and use it in GitHub Desktop.
Script to check AWS instance offers in regions
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
#!/bin/bash | |
if [ "$#" == "0" ]; then | |
echo "Usage: $0 <instance type prefix> [region]" | |
exit 1 | |
fi | |
INSTANCE_TYPE=$1 | |
if [ -z "$2" ]; then | |
REGIONS=$(aws ec2 describe-regions \ | |
--query 'Regions[*]|sort_by(@, &RegionName)|[].[RegionName]' --output text) | |
else | |
REGIONS=$2 | |
fi | |
while read -r REGION; do | |
TYPES=$(aws ec2 describe-instance-type-offerings --no-cli-pager \ | |
--location-type region --region $REGION --output text --query \ | |
'InstanceTypeOfferings[]|sort_by(@, &InstanceType)[?starts_with(InstanceType, `'$INSTANCE_TYPE'`)].[`" "`, InstanceType]|map(&[join(``, @)], @)' ) | |
if [ ! -z "$TYPES" ]; then | |
echo $REGION | |
echo "$TYPES" | |
fi | |
done <<< "$REGIONS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment