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"
}
]
}
]
}
- Node.js >= 12.18.0
- MongoDB >= 3.6
- 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
- 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:
npm run update:dev -- --only=aws:bulk
npm run dev
npm build
npm run start
You can now access the GraphQL Playground at http://localhost:4000/graphql.
- Additional vendors
- A more user-friendly API - this will require adding mappings for all AWS services.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.