├── LICENSE ├── README.md └── price_check /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Bjorn Stange 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ec2-price-check 2 | Gives a quick price check for an instance type 3 | Provides hourly rate in USD for Linux EC2 instances 4 | 5 | ## Dependencies 6 | * curl 7 | 8 | ## Arguments 9 | ### help (-h|--help) 10 | Prints help 11 | ``` 12 | price_check -h 13 | ``` 14 | 15 | ### region (-r|--region) 16 | Specifies region for which you would like the price\ 17 | Default: us-east-1 18 | ``` 19 | price_check -r us-west-1 r4.large 20 | ``` 21 | 22 | ## Example 23 | ``` 24 | $ price_check t2.medium 25 | 0.0464 26 | ``` 27 | 28 | ## Installation 29 | To install, simply add the `price_check` bash script to your PATH. 30 | I personally like to do this via a `~/bin` directory, but you are free to do it however you wish. 31 | 32 | Powered By: [https://github.com/Bjorn248/graphql_aws_pricing_api](https://github.com/Bjorn248/graphql_aws_pricing_api) 33 | -------------------------------------------------------------------------------- /price_check: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This translates region strings 4 | # e.g. us-west-2 5 | # into the regions that the GraphQL API expects 6 | read -r -d '' region_lookup_map << EOF 7 | us-gov-west-1,AWS GovCloud (US) 8 | us-gov-east-1,AWS GovCloud (US) 9 | us-east-2,US East (Ohio) 10 | us-east-1,US East (N. Virginia) 11 | us-west-1,US West (N. California) 12 | us-west-2,US West (Oregon) 13 | af-south-1,Africa (Cape Town) 14 | ap-east-1,Asia Pacific (Hong Kong) 15 | ap-south-2,Asia Pacific (Hyderabad) 16 | ap-southeast-3,Asia Pacific (Jakarta) 17 | ap-southeast-4,Asia Pacific (Melbourne) 18 | ap-south-1,Asia Pacific (Mumbai) 19 | ap-northeast-3,Asia Pacific (Osaka) 20 | ap-northeast-2,Asia Pacific (Seoul) 21 | ap-southeast-1,Asia Pacific (Singapore) 22 | ap-southeast-2,Asia Pacific (Sydney) 23 | ap-northeast-1,Asia Pacific (Tokyo) 24 | ca-central-1,Canada (Central) 25 | ca-west-1,Canada West (Calgary) 26 | eu-central-1,Europe (Frankfurt) 27 | eu-west-1,Europe (Ireland) 28 | eu-west-2,Europe (London) 29 | eu-south-1,Europe (Milan) 30 | eu-west-3,Europe (Paris) 31 | eu-south-2,Europe (Spain) 32 | eu-north-1,Europe (Stockholm) 33 | eu-central-2,Europe (Zurich) 34 | il-central-1,Israel (Tel Aviv) 35 | me-south-1,Middle East (Bahrain) 36 | me-central-1,Middle East (UAE) 37 | sa-east-1,South America (São Paulo) 38 | cn-north-1,China (Beijing) 39 | cn-northwest-1,China (Ningxia) 40 | EOF 41 | 42 | usage="$(basename "$0") [-h|--help] [-r|--region] 43 | 44 | Examples: 45 | price_check t2.medium 46 | price_check -r us-west-1 r4.large" 47 | 48 | 49 | POSITIONAL=() 50 | 51 | # If no arguments given, print help 52 | if [ $# -eq 0 ]; then 53 | echo "$usage" 54 | exit 0 55 | fi 56 | 57 | while [[ $# -gt 0 ]] 58 | do 59 | key="$1" 60 | 61 | case $key in 62 | -h|--help) 63 | echo "$usage" 64 | exit 0 65 | ;; 66 | -r|--region) 67 | REGION="$2" 68 | shift # past argument 69 | shift # past value 70 | ;; 71 | *) # unknown option 72 | POSITIONAL+=("$1") # save it in an array for later 73 | shift # past argument 74 | ;; 75 | esac 76 | done 77 | set -- "${POSITIONAL[@]}" # restore positional parameters 78 | 79 | if [ "$REGION" = "" ]; then 80 | REGION="us-east-1" 81 | fi 82 | 83 | if ! echo "$region_lookup_map" | grep -q "$REGION"; then 84 | echo "Could not find region: $REGION" 85 | exit 1 86 | fi 87 | 88 | graphql_region=$(echo "$region_lookup_map" | grep "$REGION" | cut -d',' -f2) 89 | 90 | instance_type=$1 91 | 92 | header="Content-Type: application/json" 93 | 94 | read -r -d '' req_body << EOF 95 | { 96 | "query": "{ AmazonEC2( \ 97 | Location:\"${graphql_region}\", \ 98 | TermType:\"OnDemand\", \ 99 | InstanceType:\"${instance_type}\", \ 100 | OS:\"Linux\", \ 101 | Tenancy:\"Shared\", \ 102 | CapacityStatus:\"Used\", \ 103 | PreInstalledSW:\"NA\") \ 104 | {PricePerUnit Unit Currency}}", \ 105 | "variables":"","operationName":"" 106 | } 107 | EOF 108 | 109 | price=$(curl -sS -H "${header}" -X POST -d "${req_body}" \ 110 | https://fvaexi95f8.execute-api.us-east-1.amazonaws.com/Dev/graphql/ \ 111 | | cut -d':' -f 4 | cut -d',' -f 1 | cut -d'"' -f2) 112 | 113 | if [ "$price" = "" ]; then 114 | echo "Could not find instance type: $instance_type" 115 | exit 1 116 | fi 117 | 118 | echo "$price" 119 | --------------------------------------------------------------------------------