This document explains how to send budget notifications to Slack.
Budgets are typically configured to send email notifications. However, email isn't always the best way to stay up to date on your cloud costs, particularly if your budget is critical and time sensitive. With programmatic notifications, you can forward your budget messages to other mediums, such as Slack.
Before you begin
Before you begin, you must complete the following tasks:
Set up a Slack channel and permissions
The first step is to create your Slack workspace and the bot user tokens that are used to call the Slack API. API tokens can be managed at https://api.slack.com/apps. For detailed instructions, see Bot Users on the Slack site.
Set up a Cloud Run function
Complete the steps in Create a Cloud Run function. Ensure that the Trigger type is set to the same Pub/Sub topic that your budget will use.
Add the following dependencies:
Node.js
Copy the following to your
package.json
:Python
Copy the following to your
requirements.txt
:Copy the following code into your Cloud Run function to post budget notifications to a Slack chat channel using the Slack API:
Node.js
Python
Ensure the following Slack API postMessage parameters are set correctly:
- Bot User OAuth access token
- Channel name
Test your function
To ensure your function works as expected, follow the steps in Test a Cloud Run function.
If successful, a message will show up in Slack.
What's next
Review other programmatic notification examples to learn how to do the following:
- Listen to your notifications
- Control resource usage with notifications
- Disable billing usage with notifications