rhakbari / aws-prices-graphql

AWS Price List GraphQL API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aws-prices-graphql: AWS Price List GraphQL API

AWS offers a Bulk API, which returns large JSON files containing all price points for each service or a Query API, which requires AWS credentials and an IAM user.

This project creates a GraphQL API using the data from the AWS Price List Bulk API.

This project currently uses a generic GraphQL schema to represent all AWS products. Future work might move to using schemas for each distinct AWS product.

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://aws-prices-graphql.alistair.scot/graphql. This is running on minimal infrastructure so is not guaranteed to always be available.

query {
  products(
    filter: {
      attributes: [
        { key: "servicecode", value: "AmazonEC2" },
        { key: "instanceType", value: "t3.micro" },
        { key: "location", value: "US East (N. Virginia)" }
      ]
    },
  ) {
    attributes { key, value }
    onDemandPricing {
      priceDimensions {
        pricePerUnit {
          USD
        }
      }
    }
  }
}

Get the hourly on-demand price of a Linux EC2 t3.micro instance in US East:

Request:

query {
  products(
    filter: {
      attributes: [
        { key: "servicecode", value: "AmazonEC2" },
        { key: "instanceType", value: "t3.micro" },
        { key: "location", value: "US East (N. Virginia)" }
        { key: "tenancy", value: "Shared" }
        { key: "operatingSystem", value: "Linux"}
        { key: "capacitystatus", value: "Used" }
        { key: "preInstalledSw", value: "NA"}
      ]
    },
  ) {
    onDemandPricing {
      priceDimensions {
        pricePerUnit {
          USD
        }
      }
    }
  }
}

Response:

{
  "data": {
    "products": [
      {
        "onDemandPricing": [
          {
            "priceDimensions": [
              {
                "pricePerUnit": {
                  "USD": "0.0104000000"
                }
              }
            ]
          }
        ]
      }
    ]
  }
}

Getting started

Prerequisites

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

Installation

  1. Clone the repo
git clone https://github.com/aliscott/aws-prices-graphql.git
cd aws-prices-graphql
  1. Add a .env file to point to your MongoDB server, e.g.
MONGODB_URI=mongodb://localhost:27017/awsPricing
  1. Install the npm packages
npm install
  1. Download the AWS pricing files into the data directory. Note: this downloads about 1.8 GB of data
npm run downloadPrices
  1. Load the prices into MongoDB
npm run loadPrices

Usage

Running

npm start

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

Future work

  • Product-specific schemas - can we auto-generate these?

Contributing

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

License

MIT

About

AWS Price List GraphQL API

License:MIT License


Languages

Language:JavaScript 100.0%