1

I have used the sample code in the GCP guide https://cloud.google.com/billing/docs/how-to/notify to create a Python Cloud Function to send out messages and disable billing for a project whenever a budget alert indicates that the project is exceeding a spend limit. The budget alert uses pubsub to activate the Cloud Function.

Using the sample code approach the Cloud Function is within the project being monitored. The project is owned by a specific Google account and it is the same Google account that owns the budget that uses pubsub when a budget alert is issued.

I would like to provide the Cloud Function to other Google accounts as a service. What I want to happen is when a budget alert is triggered in a Google account other than my own then a pubsub message is sent to a Cloud Function of one of my projects under my Google account.

It seems to me that this is what pubsub is for but whenever I try to configure this approach I find that the only combination I can get to work is where the budget and Cloud Function are under the same Google account.

I wonder if the solution is to be found in IAM and setting up an Organization structure. I am finding it difficult to get to grips with IAM. Any suggestions gratefully received, even a "this is not possible" would be helpful.

Thanks

DaveEnVelo
  • 41
  • 1
  • 1
    This could be a starting point: https://faun.pub/capping-costs-on-gcp-for-many-projects-with-a-budget-for-many-months-without-paying-a-penny-dc461525c2d2 – dany L Oct 21 '21 at 14:48

1 Answers1

0

You would need to create a customized budget alert to create an email notification channel.

For Cloud Billing budget alerts, you must configure Email notification channels. Other types of notification channels are not supported.

In this section, you'll find a link on "how to send slack notifications," and even if you are not using it, the documentation guides How to set up and enable Pub/Sub programmatic notifications. It will ask you to create a pub/sub topic and then connect a cloud billing budget. Once you are done with that in the Cap (disable) billing to stop usage...

Before you start working with this example, make sure you have done the following:

Enable the Cloud Billing API. Your Cloud Function needs to call the Cloud Billing API to disable Cloud Billing for a project.

Set up a budget to monitor project costs, and enable budget notifications.

Finally, you can write a cloud function to cap your budget based on the alerts. So, in order for it to work on different accounts, you need to first create a pub/sub topic and the customized alerts.

Alex
  • 778
  • 1
  • 15