Skip to content

Instantly share code, notes, and snippets.

@pjoe
Created June 13, 2022 07:58
Show Gist options
  • Save pjoe/333736a5d3d64cd0be869bf7451ad522 to your computer and use it in GitHub Desktop.
Save pjoe/333736a5d3d64cd0be869bf7451ad522 to your computer and use it in GitHub Desktop.
Script to check AWS instance offers in regions
#!/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