Last active
February 21, 2021 14:04
-
-
Save jan-swiecki/6b7e8054f731577f4e61d3df6652ca22 to your computer and use it in GitHub Desktop.
aws-pricing
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 | |
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 | |
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 | |
ln -s "$PWD/aws-pricing" ~/.local/bin/aws-pricing |
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 | |
rm ~/.local/bin/aws-pricing || true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment