Skip to content

Instantly share code, notes, and snippets.

@jan-swiecki
Last active February 21, 2021 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan-swiecki/6b7e8054f731577f4e61d3df6652ca22 to your computer and use it in GitHub Desktop.
Save jan-swiecki/6b7e8054f731577f4e61d3df6652ca22 to your computer and use it in GitHub Desktop.
aws-pricing
#!/bin/bash
set -eo pipefail
if [ -z "$1" ]; then
cat <<EOF
usage:
aws-pricing <instance_type> display pricing per availability zone
aws-pricing --instance-types [pattern] show all available instance types
filtered by optional pattern
EOF
exit
fi
if [ "$1" == "--instance-types" ]; then
aws ec2 describe-spot-price-history help | egrep '\s{5,}[a-z\-]+[0-9]+[a-z0-9]*\.[0-9]*[a-z]+' \
| sed -E -e 's/^[[:blank:]]+//g' | grep "$2"
exit
fi
regions=`aws ec2 describe-regions --query 'Regions[].RegionName[]' --output text`
for region in $regions; do
aws ec2 describe-spot-price-history --instance-types "$1" \
--max-items 10 \
--start-time `date +%Y%m%dT%H:%M:%S` \
--product-description 'Linux/UNIX' \
--region "$region" \
--query 'SpotPriceHistory[].{AvailabilityZone: AvailabilityZone, SpotPrice: SpotPrice, Timestamp: Timestamp}' \
--output text | {
while read line; do
echo "$1 $region $line"
done
}
done
#!/bin/bash
ln -s "$PWD/aws-pricing" ~/.local/bin/aws-pricing
#!/bin/bash
rm ~/.local/bin/aws-pricing || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment