Search code examples
google-cloud-platformgoogle-cloud-billing

How to create a budget with enabling notification channel by using Cloud Billing Budget API


Able to create budgets by leveraging Cloud Billing Budget API but couldn't able to add / enable notification channels for the budget to get an alert .

Please advise .


Solution

  • The default functionality is to send alerts on budget threshold to users with the Billing Account Administrator or Billing Account User role. The console UI allows you to also map Monitoring notification channels, that enables the functionality of customizing the email addresses where threshold alerts get sent. I am not aware of any way to do this through the API.

    You can create ThresholdRules through the API, that then send automatic emails to Billing Account Admins and Users (as per the default behaviour). This does not help you if you need a custom email or some other channel to send the notification.

    The other thing you can do is configure your own pub/sub topic to receive all updates related to budgets. You can then map a function to programmatically to the pub/sub topic to do something on updates. This is documented at https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications

    You can also take a look at https://cloud.google.com/billing/docs/reference/budget/rpc/google.cloud.billing.budgets.v1beta1#google.cloud.billing.budgets.v1beta1.AllUpdatesRule.