当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

cloud-pricing-api

授权协议 Apache-2.0 License
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 谷梁星雨
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Cloud Pricing API

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 register.

  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.

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

  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 register

    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 up. This will create three containers: PostgreSQL DB, Cloud Pricing API, 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 init_job_1: Completed: downloading DB data.

  6. 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
  7. 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
  8. 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
  9. The home page for the Cloud Pricing API, http://localhost:4000, shows if prices are up-to-date and some statistics.

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.

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. Longer term, the Terraform provider model is making us wonder if we could move towards an architecture for the Cloud Pricing API where community-supported cloud vendors could also be added.

License

Apache License 2.0

  • gdb -iex Python is an excellent programming language for creating data visualizations. Python是用于创建数据可视化的优秀编程语言。 However, working with a raw programming language like Python (instead of more sophistica

  • 历史说明 IBM 最早的公有云叫SCE. 后来合并入SoftLayer. 2014.10收购了SoftLayer, 每年投入10多亿美金,扩容机房,到2018年底,全球59个节点,业内第一。 IBM原来的SoftLayer IaaS 和Bluemix PaaS是分开的. 为了统一用户,界面,账单和加上SDDC等新功能一直在开发。 2018.12新网站推出, 新的网站叫 IBM Cloud. htt

 相关资料
  • Pricing Tables 是一款 jQuery 表格插件,可以简单响应的定价表格,有3种不同的风格,当跳转到不同的计划时,会有生动的动画。

  • WooCommerce Dynamic Pricing插件可以实现动态价格,比如一个产品买1-10个单价10元,买11-20个单价9元。这个插件缺少一个功能——在产品页面展示动态价格表,本文介绍添加WooCommerce Dynamic Pricing动态价格表的方法。 WooCommerce Dynamic Pricing动态价格表 该插件默认不能在产品页面显示价格表,要将产品加入购物车,再去购

  • Cloudfoundry的Spring Cloud可以轻松地在Cloud Foundry(平台即服务)中运行 Spring Cloud应用程序 。Cloud Foundry有一个“服务”的概念,它是“绑定”到应用程序的中间件,本质上为其提供包含凭据的环境变量(例如,用于服务的位置和用户名)。 spring-cloud-cloudfoundry-web项目为Cloud Foundry中的webapp

  • IBM、微软、Zend Technologies发起了一个开源项目Simple Cloud API,让程序员在云计算环境中运行一般的应用,和在不需要修改代码来访问云计算环境的情况下,使用PHP语言开发云计算应用程序。Zend Framework(或称Zend Cloud)将作为该PHP项目的实现。

  • 我正在构建一个以谷歌云作为后端的移动应用程序。它存储关于餐馆的信息,包括他们的菜单。我需要根据菜单项和地理位置进行搜索。 我对使用哪种谷歌云解决方案相当困惑。最初,我打算使用Google App Engine和Cloud Datastore来存储数据,但后来发现,它不支持地理定位搜索,即使我使用App Engine搜索api,我也不会得到“Like”文本搜索。关于使用云SQL,我担心它的价格。我也

  • 我的索引中有这个代码。当我向云firestore创建数据时,其他用户会收到一个通知。但这不是工作 const函数=需要('Firebase函数'); const admin=需要('Firebase管理'); 管理初始化EAPP();