Notify CloudWatch alarms to Slack with AWS Chatbot!
table of contents
*Miki Jet (Kobe Maya)
Hello!
My name is Hide, the ramen king of Beyond Osaka Office.
This is my 5th post.
Last time, I talked about notifying CloudWatch alarms to Teams/Chatwork, which I recently implemented in a project.
This time, we will talk about how to notify CloudWatch alarms to Slack using AWS Chatbot.
In my last blog post, I wrote an interesting article about using AWS Lambda and Python to get notifications, so if you're interested, please take a look!
Configuration diagram
The configuration diagram is shown above.
Obtain EC2 metrics with CloudWatch and notify SNS when an alarm occurs. SNS then sends the alarm sent from CloudWatch to Chatbot.
The Chatbot then sends the alarm to Slack. It is easier to implement than Teams/Chatwork because it does not use AWS Lambda.
Let's work hard and build together!
Construction steps
① SNS
①-①: SNS > Topics > Click Create Topic
①-②: Specify the following information and click [Create topic]
● Type: Standard
● Name: Please enter your favorite name
①-③: Confirm that it was created successfully
② Chatbot
②-①: Chatbot > Configured clients > Click [Set new client]
②-②: Select Slack and click [Settings]
②-③: Sign in to the workspace
*If you have already logged in, you will see the screen below.
If you want to create a new workspace, click [Add another workspace] from the top right.
*How to find your Slack workspace URL is as follows.
Reference: Check the Slack URL of the workspace you are participating in
1. Click on the name of the workspace you are participating in
2. Under the workspace name, find the Slack URL of the workspace you're joining.
②-④: Log in to the specified workspace
②-⑤: Allow permissions
②-⑥: After confirming approval, click [Set new channel]
②-⑦: Enter the setting name
*Please set any setting name.
*If you want to record logs to CloudWatch Logs, please check the box.
②-⑧: Select Slack channel
*Select public or private, then select the channel name.
②-⑨: Set role
● Channel IAM role
A role that grants the same permissions to all members in a Slack channel.
● User role
A role that grants different permissions to each member of a Slack channel.
②-⑩: Set channel IAM role
*For the channel IAM role, select [Create an IAM role using a template].
*Please choose a role name of your choice.
②-⑪: Set policy template
②-⑫: Channel guardrail policy
● Channel guardrail policy
This is a policy that takes precedence over channel IAM roles and user roles.
If you turn on CloudWatchReadOnlyAccess, you can view the graph.
②-⑬: Notification settings
*Please specify the topic you created on SNS.
③ CloudWatch
*We will proceed with the assumption that EC2 has been created.
③-①:Cloudwatch>Alarm>Click [Create alarm]
Select your favorite metrics
③-③: Select alarm condition
③-④: Notification settings
③-⑤: Specify the alarm name
③-⑥Click [Create alarm]
④ Notification test
④-①: Check if the alarm is on.
④-②: Check whether the alarm has been notified
*If you set the threshold so that no alert occurs, you can check the recovery as shown below.
summary
This time, we introduced an article on how to notify Slack of CloudWatch alarms using Chatbot.
When sending alarm notifications in Slack, you can easily send notifications using a chatbot.
The graph URL and graph image are also included, so the alarm is very easy to read!
Slack is easy to implement, but if you want to notify alarms using Teams/Chatwork, you will have to write Python code with AWS Lambda, prepare webhooks, and take a lot of effort...
I would really like AWS to support Chatbots in Teams/Chatwork as well (although it probably won't be possible...)