Skip to content

3mard/cloud-pricing-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloud Pricing API

This project aims to create a GraphQL cloud pricing API. Currently only AWS resources are supported, but future support for other cloud vendors is planned.

This is an early stage project, pull requests to add resources/fix bugs are welcome.

Table of Contents

Example requests

Get all t3.micro prices in US East, this returns 30+ results. Try it yourself by pasting the query into https://pricing.infracost.io/graphql.

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
  1. Install the npm packages
npm install
  1. Update the pricing data Note: this downloads about 1.8 GB of data
npm run update

Usage

Running

npm 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published