Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vadirajks/15f499e4444c488f25f475b0a249980c to your computer and use it in GitHub Desktop.
Save vadirajks/15f499e4444c488f25f475b0a249980c to your computer and use it in GitHub Desktop.
AWS Pricing API ワンライナー
$ aws pricing describe-services \
  --region us-east-1 \
| jq -r '.Services[] | select (.ServiceCode=="AmazonEC2") | .AttributeNames[]' \
| sort
LeaseContractLength
OfferingClass
PurchaseOption
capacitystatus
clockSpeed
currentGeneration
dedicatedEbsThroughput
ebsOptimized
ecu
elasticGpuType
enhancedNetworkingSupported
gpu
gpuMemory
group
groupDescription
instance
instanceCapacity10xlarge
instanceCapacity12xlarge
instanceCapacity16xlarge
instanceCapacity18xlarge
instanceCapacity24xlarge
instanceCapacity2xlarge
instanceCapacity32xlarge
instanceCapacity4xlarge
instanceCapacity8xlarge
instanceCapacity9xlarge
instanceCapacityLarge
instanceCapacityMedium
instanceCapacityXlarge
instanceFamily
instanceType
intelAvx2Available
intelAvxAvailable
intelTurboAvailable
licenseModel
location
locationType
maxIopsBurstPerformance
maxIopsvolume
maxThroughputvolume
maxVolumeSize
memory
networkPerformance
normalizationSizeFactor
operatingSystem
operation
physicalCores
physicalProcessor
preInstalledSw
processorArchitecture
processorFeatures
productFamily
provisioned
servicecode
servicename
storage
storageMedia
tenancy
termType
usagetype
vcpu
volumeType
$ aws pricing get-attribute-values \
  --region us-east-1 \
  --service-code AmazonEC2 \
  --attribute-name location \
| jq -r '.AttributeValues[].Value' \
| sort
AWS GovCloud (US)
Asia Pacific (Mumbai)
Asia Pacific (Osaka-Local)
Asia Pacific (Seoul)
Asia Pacific (Singapore)
Asia Pacific (Sydney)
Asia Pacific (Tokyo)
Canada (Central)
EU (Frankfurt)
EU (Ireland)
EU (London)
EU (Paris)
South America (Sao Paulo)
US East (N. Virginia)
US East (Ohio)
US West (N. California)
US West (Oregon)
$ aws pricing get-products \
  --region us-east-1 \
  --service-code AmazonEC2 \
  --filters \
    "Type=TERM_MATCH,Field=productFamily,Value=Compute Instance" \
    "Type=TERM_MATCH,Field=instanceType,Value=t3.medium" \
    "Type=TERM_MATCH,Field=location,Value=Asia Pacific (Tokyo)" \
    "Type=TERM_MATCH,Field=operatingSystem,Value=Linux" \
    "Type=TERM_MATCH,Field=operation,Value=RunInstances" \
| jq -r '.PriceList[]' | jq '.product'
{
  "productFamily": "Compute Instance",
  "attributes": {
    "memory": "4 GiB",
    "vcpu": "2",
    "capacitystatus": "Used",
    "instanceType": "t3.medium",
    "tenancy": "Shared",
    "usagetype": "APN1-BoxUsage:t3.medium",
    "locationType": "AWS Region",
    "storage": "EBS only",
    "normalizationSizeFactor": "2",
    "instanceFamily": "General purpose",
    "operatingSystem": "Linux",
    "servicecode": "AmazonEC2",
    "physicalProcessor": "Intel Skylake E5 2686 v5 (2.5 GHz)",
    "licenseModel": "No License required",
    "ecu": "Variable",
    "currentGeneration": "Yes",
    "preInstalledSw": "NA",
    "networkPerformance": "Low to Moderate",
    "location": "Asia Pacific (Tokyo)",
    "servicename": "Amazon Elastic Compute Cloud",
    "processorArchitecture": "64-bit",
    "operation": "RunInstances"
  },
  "sku": "77PTRYZ5MAUP8HU6"
}
$ aws pricing get-products \
  --region us-east-1 \
  --service-code AmazonEC2 \
  --filters \
    "Type=TERM_MATCH,Field=productFamily,Value=Compute Instance" \
    "Type=TERM_MATCH,Field=instanceType,Value=t3.medium" \
    "Type=TERM_MATCH,Field=location,Value=Asia Pacific (Tokyo)" \
    "Type=TERM_MATCH,Field=operatingSystem,Value=Linux" \
    "Type=TERM_MATCH,Field=operation,Value=RunInstances" \
| jq -r '.PriceList[]' | jq '.terms.OnDemand'
{
  "77PTRYZ5MAUP8HU6.JRTCKXETXF": {
    "priceDimensions": {
      "77PTRYZ5MAUP8HU6.JRTCKXETXF.6YS6EN2CT7": {
        "unit": "Hrs",
        "endRange": "Inf",
        "description": "$0.0544 per On Demand Linux t3.medium Instance Hour",
        "appliesTo": [],
        "rateCode": "77PTRYZ5MAUP8HU6.JRTCKXETXF.6YS6EN2CT7",
        "beginRange": "0",
        "pricePerUnit": {
          "USD": "0.0544000000"
        }
      }
    },
    "sku": "77PTRYZ5MAUP8HU6",
    "effectiveDate": "2018-09-01T00:00:00Z",
    "offerTermCode": "JRTCKXETXF",
    "termAttributes": {}
  }
}
$ aws pricing get-products \
  --region us-east-1 \
  --service-code AmazonEC2 \
  --filters \
    "Type=TERM_MATCH,Field=productFamily,Value=Compute Instance" \
    "Type=TERM_MATCH,Field=instanceType,Value=t3.medium" \
    "Type=TERM_MATCH,Field=location,Value=Asia Pacific (Tokyo)" \
    "Type=TERM_MATCH,Field=operatingSystem,Value=Linux" \
    "Type=TERM_MATCH,Field=operation,Value=RunInstances" \
| jq -r '.PriceList[]' \
| jq -r '.terms.OnDemand | .. | select(.priceDimensions?) | .priceDimensions | .. | select(.pricePerUnit?) | .pricePerUnit.USD'
0.0544000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment