The following diagram shows an overview of the architecture.
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:
- 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.
- 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.
It should take around 15 mins to deploy the Cloud Pricing API. Two deployment methods are supported:
- If you have a Kubernetes cluster, we recommend using our Helm Chart.
- If you prefer to deploy in your machine or a VM, we recommend using our Docker compose file.
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.
The Infracost CLI uses a single API key to authenticate with the Cloud Pricing API. You control the API key and can rotate it in the Cloud Pricing API by updating the
SELF_HOSTED_INFRACOST_API_KEY environment variable and restarting the application.
When using the CLI locally, run the following two required commands to point your CLI to your self-hosted Cloud Pricing API:
In CI/CD systems, set the following two required environment variables:
Your self-hosted Cloud Pricing API endpoint (e.g. http://localhost:4000 if running locally with Docker compose), will show if prices are up-to-date and some statistics.
Our Helm chart comes with cdefault ecommendations about resource requests/limits for the API and price update job pods:
- Minimum: 50 millicores, 64MB of RAM
- Limit per pod: 1 core, 512MB of RAM
- Price update job:
- Minimum: 50 millicores, 128MB of RAM
- Limit per pod: 200 millicore, 640MB of RAM
For the PostgreSQL DB, a small instance with 2 vCPU and 2GB of RAM should be enough.
If you had previously deployed the Cloud Pricing API that used MongoDB, we recommend you:
- Follow the above instructions to deploy the new version using our Helm Chart or our Docker compose file.
- Upgrade the Infracost CLI on your dev machine to the latest version.
- Point your CLI to your new self-hosted Cloud Pricing API using the two required commands. Test it by generating a cost estimate.
- Update your CI/CD systems to point to the new self-hosted Cloud Pricing API using the required two environment variables. If you're not using our official CI/CD integrations, you should also upgrade your integration to use the latest version of the CLI (the official integrations use the latest released CLI version by default).
- Destroy your old instance of the Cloud Pricing API.