Send alert to Slack when the cost exceeds the threshold set in Cloud Billing.
This system uses
- Cloud Billing
- Pub/Sub
- Google Cloud Functions
- Slack API
- Set budgets and budget alerts
- in this example, alert thresholds are set as 20%, 50%, and 100% of the budget.
- Create a Pub/Sub topic and register it to the budget alert.
- Make Slack app and get Incoming Webhook URI
Enviroment variables to use in GCF runtime are set in env.yaml
file.
(sample)
SLACK_WEBHOOK_URL: <slack webhook url>
Run unit tests in your local environment.
make test
In addition to unit tests, you can run integration tests including Slack notification.
make test-all
Run the program locally and send a sample message to Slack.
make local-run
In this example, Pub/Sub topic name is cost-alert
.
You can change topic name and region from Makefile.
make deploy