Enter the bots...AWS Budget with Chatbot
I've been talkn about AWS Budgets recently and would like to dive a little further into this neat service to integrate more services that are supported by AWS Budgets. Let's face it, emails are boring, we get tones of them, there is a lot of noise in the ops world it doesn't work too well. Let's explore adding a Chatbot to Budget to get notifications through third party chat services.
If you haven't already checked out my previous post on AWS Budgets, getting setting up and using the AWS CDK + CloudFormation Deploy Stack. Swing by my previous post as this will continue on from that with the addition of AWS Chatbot.
I have selected Slack for this demo for no other reason other than it's a popular service and supported by Chatbot. You probably know what it's about by now and it's common to see out there in ops land. If you don't know, it's a messaging platform, there is a desktop and mobile client, channels, conversations etc. I'm going to assume you've already signed up for Slack and know how to get around, it's not too hard if don't so don't be alarmed.
Let's dive right in
OK, now there will be some console action in this. We need to authorize Slack and AWS Chatbot using the AWS Console.
- Jump into the AWS Console
- Head over to AWS Chatbot
3. You'll see the welcome screen, we'll add a new Slack client right off the welcome screen.
- If you're already logged in and have permission in Slack you'll be greeted with the configuration screen to permit AWS Chatbot app to connect with Slack.
- Review the permissions and hit allow
- Now you'll have a Workspace ID that we can use
Note: Notice we don't have any other configuration, that will come later
- Open up your Slack space so you can see your channels
- If you don't have a channel, create a new one
- Add the AWS app to the channel (add apps button to the left), you see AWS because we authorized it in the console
- Now we need the channel ID, the easiest way is to click on the channel and then look in the top bar with the URL is. The very end ID is the Channel ID. E.g. X10XXX1XXXX
5. You can also right click the channel and go copy link, again is the last portion of the link after the "/"
AWS CloudFormation Deploy Stack - IaC, Yay!
Like my previous post, I have supplied a CF Deploy Stack Button, simple click the button below and this will configure AWS Budgets, AWS SNS, AWS Chatbots etc for you in a neat tidy stack.
As above, here are the parameters:
- Where do you want to receive email notifications for billing alarms
- Slack Channel ID
- Slack Workspace ID
- Spend (Budget)
- This is in USD, the alarm threshold is 80% of this value
Once deployed you can head back to Slack and type @aws in your ChatOps channel and you should receive some help back.
If you're into AWS CDK the whole project is available on Github so you can synth and deploy the stack. This way you can remove some of the parameters and custom as needed.
cdk deploy --parameters firstname.lastname@example.org --parameters spend=10 --parameters workspace=XXXXMICKXXXX --parameters channel=XXXXTALKNCLOUDXXXX
The code the CDK stack (also used for the CF deploy) is, as always, open source and up on Github:
But what does it all mean?
OK, so if you're here you might be wondering what I'll end up with. This project is different from the previous where the budget was based on actual spend e.g. money spent, I have configured this one to use forecasted amounts so that you can try and get ahead of the budget. Once the forecast passes 80% of your set budget, the alarms begin!
Note: forecasted can take a little while for AWS to return
AWS Chatbot configured
If you have a look into the Chatbot console you can see the newly applied configuration:
AWS Budget hooked up to SNS and Email
If you check out Budgets you can see your budget has been set and notifications are wired up to the SNS topic:
AWS Budget hitting the threshold
Here is a example of AWS Budget hitting the budget threshold:
AWS Budget alarm in email
Not too exciting, but useful none the less:
AWS Budget alarm in Slack!!!!
And now you should receive an alarm is Slack, very cool!
Clean up (yargah!)
Because we had to setup the authorization between AWS Chatbot and Slack manually it should go without saying you'll need to remove that manually if you destroy / remove the stack.
If anyone is aware of a way to script this part in the stack I'd be keen to know, as I've seen a couple of other services like this pop in AWS.
This is free???
It's always good to look over the service FAQ's and pricing before you plan on using AWS services:
In short, yes, this won't cost a dime, you'll get two Budgets for free before you start pay a little (cents). Chatbot is actually free, no limits you pay for the underlying services. SNS free tier allows for millions of messages which isn't likely in Budget notifications.
I really wanted to highlight how neat the AWS Chatbot service, it's a free service and really offers a more modern experience over emails. It would be good if there were more services available as at the moment it is limited to AWS Chime and Slack, I am sure they'll come along soon enough. If you like AWS Chatbot be sure to have a play, what I have left out is that you can actually trigger other services like Lambda from Slack to do something in your AWS environment! Be creative!
Again, if you know how to script the authentication part of Slack and AWS Chatbot please reach out.