This project aims to create a GraphQL cloud pricing API. Currently supports AWS & Google, future support for other cloud vendors is planned.
Infracost has a hosted version of this service. To get an API key download infracost and run infracost register
.
Get all t3.micro prices in US East, this returns 30+ results. Try it yourself by pasting the following query into https://pricing.api.infracost.io/graphql - you'll need to use something like the modheader browser extension so you can set the custom HTTP header x-api-key
to your Infracost API key.
query {
products(
filter: {
vendorName: "aws",
service: "AmazonEC2",
productFamily: "Compute Instance",
region: "us-east-1",
attributeFilters: [
{ key: "instanceType", value: "t3.micro" }
]
},
) {
attributes { key, value }
prices { USD }
}
}
Get the hourly on-demand price of a Linux EC2 t3.micro instance in US East:
Request:
query {
products(
filter: {
vendorName: "aws",
service: "AmazonEC2",
productFamily: "Compute Instance",
region: "us-east-1",
attributeFilters: [
{ key: "instanceType", value: "t3.micro" },
{ key: "tenancy", value: "Shared" },
{ key: "operatingSystem", value: "Linux" },
{ key: "capacitystatus", value: "Used" },
{ key: "preInstalledSw", value: "NA" }
]
},
) {
prices(
filter: {
purchaseOption: "on_demand"
},
) { USD }
}
}
Response:
{
"products": [
{
"pricing": [
{
"USD": "0.0104000000"
}
]
}
]
}
More examples can be found in
./examples/queries
- Node.js >= 14.15.0
- MongoDB >= 4.4
- Clone the repo
git clone https://github.com/infracost/cloud-pricing-api.git
cd cloud-pricing-api
- Add a
.env
file to point to your MongoDB server, e.g.
MONGODB_URI=mongodb://localhost:27017/cloudPricing
# If using GCP
GCP_PROJECT=
GCP_API_KEY=<GCP API Key> # An API key with access to the GCP Cloud Billing API
GCP_KEY_FILE=gcp_creds.json # Credentials for a service account that has read-only access to Compute Engine.
- Install the npm packages
npm install
- Run npm build
npm run-script build
- Update the pricing data Note: this downloads several GB of data
npm run update
If you only want to download from a single source you can run:
Example: AWS Bulk
npm run update:dev -- --only=aws:bulk
Example: Azure Retail
npm run update -- --only=azure:retail
npm run dev
npm run-script build
npm run start
You can now access the GraphQL Playground at http://localhost:4000/graphql.