Cloud Pricing API: 3M prices from AWS, Azure and GCP

The Cloud Pricing API is an GraphQL-based API that includes all public prices from AWS, Azure and Google; it contains over 3 million prices! The prices are automatically updated via a weekly job.

We needed a multi-cloud pricing API that we could use to explore pricing data structures (e.g. what are the various price components for AWS EC2) and filter for specific prices for the Infracost CLI.

GraphQL is a natural fit for cloud pricing as it can model the JSON structure used by cloud vendors. This enables you to query nested JSON structures using vendor-specific parameters, and request only the attributes you need to be returned in the response. For example, you can find all prices that match AWS EC2 m3.large instance in us-east-1 (over 400 prices), then explore the 30+ attributes that AWS return to describe instances (e.g. clockSpeed or networkPerformance).

Usage

Infracost runs a hosted version of this API that you can use:

  1. Register for an API key by downloading infracost and running infracost auth login.
  2. Pass the above API key. The following example fetches the latest price for an AWS EC2 m3.large instance in us-east-1.
  • Curl request
  • GraphQL playground request
  • Response
curl https://pricing.api.infracost.io/graphql \
-X POST \
-H 'X-Api-Key: YOUR_API_KEY_HERE' \
-H 'Content-Type: application/json' \
--data '
{"query": "{ products(filter: {vendorName: \"aws\", service: \"AmazonEC2\", region: \"us-east-1\", attributeFilters: [{key: \"instanceType\", value: \"m3.large\"}, {key: \"operatingSystem\", value: \"Linux\"}, {key: \"tenancy\", value: \"Shared\"}, {key: \"capacitystatus\", value: \"Used\"}, {key: \"preInstalledSw\", value: \"NA\"}]}) { prices(filter: {purchaseOption: \"on_demand\"}) { USD } } } "}
'

Concepts

The API has two main types: Products and Prices. Each product can have many Prices. This simple high-level schema provides flexibility to model the exact values that the cloud vendor APIs return at the same time as having useful top-level product filters. The values returned by the API are the same ones that the cloud vendors return in their APIs.

The main properties of Products are:

NameAWS examplesMicrosoft Azure examplesGoogle Cloud Platform examples
vendorNameawsazuregcp
serviceAmazonEC2AWSLambdaawskmsVirtual MachinesFunctionsAzure DNSCompute EngineCloud FunctionsCloud DNS
productFamilyDedicated HostProvisioned ThroughputElastic GraphicsComputeStorageDatabasesCompute InstanceLicenseNetwork
regionus-east-1cn-north-1us-gov-east-1eastusuknorthUS Govus-east1europeaustralia-southeast1
attributes(array of key-value pairs)usagetype: UGE1-Lambda-Edge-RequestclockSpeed: 2.5 GHzproductName: Premium FunctionsmeterName: vCPU DurationmachineType: n2-highmem-64description: Static Ip Charge

The main properties of Prices are:

NameDescriptionExample
USDPrice from the cloud vendor in the preferred ISO 4217 currency code (e.g. EUR, BRL or INR). For non-USD currencies, prices are converted from USD to the preferred currency at query time.USD: 0.2810000000
unitUnit for the priceunit: Hrs
descriptionAny additional descriptiondescription: Upfront Fee
startUsageAmountStart usage amount for price tier, only applicable for tiered pricingstartUsageAmount: 0
endUsageAmountEnd usage amount for price tier, only applicable for tiered pricingendUsageAmount: 10000
purchaseOptionPurchase option varies between vendorson_demandreservedspotConsumptionpreemptible
termPurchaseOptionTerm of the purchase optiontermPurchaseOption: All Upfront
termLengthLength of the purchase optiontermLength: 1yr
termOfferingClassOffering class or type of the termtermOfferingClass: standard

Similar Posts