This terraform scripts to deploy a Lambda function periodically triggered by CloudWatch Events. The Lambda Function retrieve your current month's AWS cost from Cost Explorer API responses and posts message to any Slack Channel using Incoming Webhooks.
This Lambda function is written in Python3. The Python program was created with reference to Blueprints.
See the links below.
- Setup Terraform
- In terraform.tfvars, you will set the channel of your choice and Webhook URL.
- The left side border color of the message changes with threshold of cost. (The unit is USD)
region = "<REGION>"
slack_channel_name = "<YOUR SLACK CHANNEL>" # ex) general (without '#')
slack_webhook_url = "<YOUR SLACK WEBHOOK URL>" # ex) hooks.slack.com/services/XXXXXXX (without 'https://')
cloudwatch_cron = "cron(0 0 */3 * ? *)" # CAUTION: Cost Explorer API cost for each API call is $0.01
lambda_function_name = "lambda-function"
lambda_handler_name = "lambda_handler"
billing_cost_type = "UnblendedCost"
billing_threshold_warning = 80
billing_threshold_danger = 100
- AWS Key Management Service (KMS) costs $1/month.
- Cost Explorer API cost for each API call is $0.01.
- It does not correspond to the response of the multiple set of results of Cost Explorer API. See get_cost_and_usage
MIT