All Projects → infracost → cloud-pricing-api

infracost / cloud-pricing-api

Licence: Apache-2.0 license
GraphQL API for cloud pricing. Contains over 3M public prices from AWS, Azure and GCP. Self-updates prices via an automated weekly job.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
EJS
674 projects
CSS
56736 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to cloud-pricing-api

iris3
An upgraded and improved version of the Iris automatic GCP-labeling project
Stars: ✭ 38 (-86.48%)
Mutual labels:  gcp, cloud-cost
handbook.vantage.sh
The Cloud Cost Handbook is a free, open-source, community-supported set of guides meant to help explain often-times complex pricing of public cloud infrastructure and service providers in plain english.
Stars: ✭ 265 (-5.69%)
Mutual labels:  finops, cloud-cost
resoto
Resoto - Find leaky resources, manage quota limits, detect drift, and clean up!
Stars: ✭ 562 (+100%)
Mutual labels:  gcp, finops
Ec2instances.info
Amazon EC2 instance comparison site
Stars: ✭ 3,619 (+1187.9%)
Mutual labels:  finops, cloud-cost
Infracost
Cloud cost estimates for Terraform in pull requests💰📉 Love your cloud bill!
Stars: ✭ 4,505 (+1503.2%)
Mutual labels:  gcp, cloud-cost-estimates
auth
A GitHub Action for authenticating to Google Cloud.
Stars: ✭ 567 (+101.78%)
Mutual labels:  gcp
m2.Price
Magento2. Rounding Price to Prettier Value for Multi-Currency Stores.
Stars: ✭ 60 (-78.65%)
Mutual labels:  price
DevSecOps
Ultimate DevSecOps library
Stars: ✭ 4,450 (+1483.63%)
Mutual labels:  gcp
hipaa-cloud-resources
HIPAA Cloud Resources -- a structured guide on usage of cloud services in the healthcare industry
Stars: ✭ 23 (-91.81%)
Mutual labels:  gcp
grucloud
Generate diagrams and code from cloud infrastructures: AWS, Azure,GCP, Kubernetes
Stars: ✭ 76 (-72.95%)
Mutual labels:  gcp
drone-gcloud-helm
Drone 0.5 plugin to create and deploy Helm charts for Kubernetes in Google Cloud.
Stars: ✭ 13 (-95.37%)
Mutual labels:  gcp
cloud-speech-and-vision-demos
A set of demo applications that make use of google speech, nlp and vision apis based in angular2
Stars: ✭ 35 (-87.54%)
Mutual labels:  gcp
deploy-appengine
A GitHub Action that deploys source code to Google App Engine.
Stars: ✭ 184 (-34.52%)
Mutual labels:  gcp
infrakit.gcp
Infrakit plugins for Google Cloud Platform.
Stars: ✭ 12 (-95.73%)
Mutual labels:  gcp
gcpnatha
How to set up multiple NAT gateways with Equal Cost Multi-Path (ECMP) routing and autohealing enabled for a more resilient and high-bandwidth deployment using Deployment Manager.
Stars: ✭ 16 (-94.31%)
Mutual labels:  gcp
gisjogja
GISJOGJA - aplikasi web based sistem informasi geografis (SIG) / GIS wisata kota JOGJA - www.firstplato.com
Stars: ✭ 17 (-93.95%)
Mutual labels:  gcp
sops-operator
A Kubernetes operator for Mozilla SOPS
Stars: ✭ 23 (-91.81%)
Mutual labels:  gcp
push-to-gcr-github-action
An action that build docker image and push to Google Cloud Registry and Google Artifact Registry.
Stars: ✭ 43 (-84.7%)
Mutual labels:  gcp
paving
Terraform templates for paving infrastructure to deploy the Pivotal Platform.
Stars: ✭ 43 (-84.7%)
Mutual labels:  gcp
gcp-dl
Deep Learning on GCP
Stars: ✭ 27 (-90.39%)
Mutual labels:  gcp

Cloud Pricing API

Community Slack channel Docker Image Docs Tweet

The Cloud Pricing API is a GraphQL-based API that includes all public prices from AWS, Azure and Google; it contains over 3 million prices! The prices are automatically updated via a weekly job. This API is used by the Infracost CLI, thus you do not need to interact with it directly, however, you can also use it independently.

Usage

Infracost runs a hosted version of this API that you can use if you prefer that:

  1. Register for an API key by downloading infracost and running infracost auth login.

  2. If you'd like to use the API independently, pass the above API key using the X-Api-Key: xxxx HTTP header when calling https://pricing.api.infracost.io/graphql. The following example curl fetches the latest price for an AWS EC2 m3.large instance in us-east-1. More examples can be found in ./examples/queries.

    Example request:

    curl https://pricing.api.infracost.io/graphql \
      -X POST \
      -H 'X-Api-Key: YOUR_API_KEY_HERE' \
      -H 'Content-Type: application/json' \
      --data '
      {"query": "{ products(filter: {vendorName: \"aws\", service: \"AmazonEC2\", region: \"us-east-1\", attributeFilters: [{key: \"instanceType\", value: \"m3.large\"}, {key: \"operatingSystem\", value: \"Linux\"}, {key: \"tenancy\", value: \"Shared\"}, {key: \"capacitystatus\", value: \"Used\"}, {key: \"preInstalledSw\", value: \"NA\"}]}) { prices(filter: {purchaseOption: \"on_demand\"}) { USD } } } "}
      '

    Example response:

    {"data":{"products":[{"prices":[{"USD":"0.1330000000"}]}]}}

    The GraphQL Playground can also be used with something like the modheader browser extension so you can set the custom HTTP header X-Api-Key to your Infracost API key.

Architecture

The following diagram shows an overview of the architecture.

Deployment overview

The pricing DB dump is downloaded from Infracost's API as that simplifies the task of keeping prices up-to-date. We have created one job that you can run once a week to download the latest prices. This provides you with:

  1. Fast updates: our aim is to enable you to deploy this service in less than 15mins. Some cloud vendors paginates API calls to 100 resources at a time, and making too many requests result in errors; fetching prices directly from them takes more than an hour.
  2. Complete updates: We run integration tests to ensure that the CLI is using the correct prices. In the past, there have been cases when cloud providers have tweaked their pricing API data that caused direct downloads to fail. With this method, we check the pricing data passes our integration tests before publishing them, and everyone automatically gets the entire up-to-date data. The aim is reduce the risk of failed or partial updates.

Deployment

It should take around 15 mins to deploy the Cloud Pricing API. Two deployment methods are supported:

  1. If you have a Kubernetes cluster, we recommend using our Helm Chart.
  2. If you prefer to deploy in a VM, we recommend using Docker compose.

The Cloud Pricing API includes an unauthenticated /health path that is used by the Helm chart and Docker compose deployments.

The PostgreSQL DB is run on a single container/pod by default, which should be fine if your high-availability requirements allow for a few second downtime on container/pod restarts. No critical data is stored in the DB and the DB can be quickly recreated in the unlikely event of data corruption issues. Managed databases, such as a small AWS RDS or Azure Database for PostgreSQL, can also be used (PostgreSQL version >= 13). Since the pricing data can be quickly populated by running the update job, you can probably start without a backup strategy.

Helm chart

See our Helm Chart for details.

Docker compose

Prerequisites

  • Docker Engine 17.09.0+

Steps

  1. Clone the repo:

    git clone https://github.com/infracost/cloud-pricing-api.git
    cd cloud-pricing-api
  2. Use the Infracost CLI to get an API key so your self-hosted Cloud Pricing API can download the latest pricing data from us:

    infracost auth login

    The key is saved in ~/.config/infracost/credentials.yml.

  3. Generate a 32 character API token that your Infracost CLI users will use to authenticate when calling your self-hosted Cloud Pricing API. If you ever need to rotate the API key, you can simply update this environment variable and restart the application.

    export SELF_HOSTED_INFRACOST_API_KEY=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
    echo "SELF_HOSTED_INFRACOST_API_KEY=$SELF_HOSTED_INFRACOST_API_KEY"
  4. Add a .env file with the following content:

    # The Infracost API from Step 2, used to download pricing data from us.
    INFRACOST_API_KEY=<API Key from Step 2>
    
    # The API key you generated in step 3, used to authenticate Infracost CLI users with your self-hosted Cloud Pricing API.
    SELF_HOSTED_INFRACOST_API_KEY=<API Key from Step 3>
  5. Run docker-compose run init_job. This will start a PostgreSQL DB container and an init container that loads the pricing data. The init container will take a few minutes and exit after the Docker compose logs show Completed: loading data into DB.

  6. Run docker-compose up api. This will start the Cloud Pricing API.

  7. Prices can be kept up-to-date by running the update job once a week, for example from cron:

    # Add a weekly cron job to update the pricing data. The cron entry should look something like:
    0 4 * * SUN docker-compose run --rm update_job npm run job:update >> /var/log/cron.log 2>&1
  8. When using the CLI locally, run the following two required commands to point your CLI to your self-hosted Cloud Pricing API:

    infracost configure set pricing_api_endpoint http://localhost:4000
    infracost configure set api_key $SELF_HOSTED_INFRACOST_API_KEY
    
    infracost breakdown --path /path/to/code
  9. In CI/CD systems, set the following two required environment variables:

    export INFRACOST_PRICING_API_ENDPOINT=https://endpoint
    export INFRACOST_API_KEY=$SELF_HOSTED_INFRACOST_API_KEY
  10. The home page for the Cloud Pricing API, http://localhost:4000, shows if prices are up-to-date and some statistics.

Stats page

We recommend you setup a subdomain (and TLS certificate) to expose your self-hosted Cloud Pricing API to your Infracost CLI users.

You can also access the GraphQL Playground at http://localhost:4000/graphql using something like the modheader browser extension so you can set the custom HTTP header X-Api-Key to your SELF_HOSTED_INFRACOST_API_KEY.

To upgrade to the latest version, run docker-compose pull followed by docker-compose up.

The environment variable DISABLE_TELEMETRY can be set to true to opt-out of telemetry.

Using a self-signed certificate

See the Infracost docs for how to configure Infracost CLI to work with a self-hosted Cloud Pricing API that uses a self-signed certificate.

Troubleshooting

Please see this section and join our community Slack channel, we'll help you very quickly 😄

Contributing

Issues and pull requests are welcome! For development details, see the contributing guide. For major changes, including interface changes, please open an issue first to discuss what you would like to change. Join our community Slack channel, we are a friendly bunch and happy to help you get started :)

Our team is currently focused on supporting AWS, Azure and GCP so we prefer not to work on adding new cloud vendors at this time. Before we accept contributors for new cloud providers, we would like to move towards a provider model where community-supported cloud vendors could also be added (similar to Terraform providers). If you'd like to prototype the provider model, please let us know!

License

Apache License 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].