Skip to content

Latest commit

 

History

History
161 lines (123 loc) · 3.46 KB

README.md

File metadata and controls

161 lines (123 loc) · 3.46 KB

Cloud Pricing API

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.

Table of Contents

Example requests

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"
        }
      ]
    }
  ]
}

Getting started

Prerequisites

  • Node.js >= 12.18.0
  • MongoDB >= 3.6

Installation

  1. Clone the repo
git clone https://github.com/infracost/cloud-pricing-api.git
cd cloud-pricing-api
  1. 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.
  1. Install the npm packages
npm install
  1. 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

Usage

Running locally

npm run dev

Running in production

npm build
npm run start

You can now access the GraphQL Playground at http://localhost:4000/graphql.

Future work

  • Additional vendors
  • A more user-friendly API - this will require adding mappings for all AWS services.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Apache License 2.0