2

Initially google provided json for the GCP pricing i.e GCP Pricing JSON . But now this json is obsolete. For fetching the pricing of different instance type with their cost and availability region, google provided Rest API as mentioned in Google Catalogue API. But I am not able to fetch the pricing as per instance type. Please guide me on this.

2 Answers2

4

At the moment the Catalogue API does not support looking up instance prices by instance type. You will have to get all the SKUs from the API and parse them yourself.

There is an open Feature Request for it here: https://issuetracker.google.com/111070261

Vi Pau
  • 337
  • 1
  • 4
0

You can also use the Infracost's Cloud Pricing API.

This is a third-party API, but it's open-source, free and with a self-host possibility with the up-to-date prices of not only GCP but also AWS and Azure resources.

A provided example GraphQL query for a specific machine type with the response:

query {
  products(
    filter: {
      vendorName: "gcp",
      service: "Compute Engine",
      productFamily: "Compute Instance",
      region: "europe-west1",
      attributeFilters: [
        { key: "machineType", value: "n1-standard-64" }
      ]
    },
  ) {
    prices(
      filter: {
        purchaseOption: "on_demand"
      },
    ) { USD }
  }
}

# Response:
# {
#   "data": {
#     "products": [
#       {
#         "prices": [
#           {
#             "USD": "3.344112"
#           }
#         ]
#       }
#     ]
#   }
# }

Note: this is not an ad, I am totally not involved with Infracost company in any way. I just find their solution much better than what GCP currently provides.

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68