CloudWatch Alarm to Slack via AWS Chatbot

·

4 min read

Monitoring and Observability are crucial elements for Production uptime and site reliability.

Whether your infrastructure is serverless, microservices, containerized or traditional monolith you cannot run away from the observability needs.

While observability became indispensable, the product you choose for observability defines how far can you go.

There are lot of contenders in this Observability market. I have listed some of them here. DataDog, DynaTrace, AppDynamics, Solarwinds, Splunk, Elastic, New Relic

But all these products come with a cost. For those who cannot afford/want these products mostly rely on cloud platform-specific tools such as CloudWatch for AWS.

In this article, we are going to see how to use AWS CloudWatch monitoring efficiently to prevent and detect application slowness

We will also learn how to send Cloud Watch alarms to Slack using AWS Chatbot integration

cloudwatch slack alarm

How CloudWatch alarms are sent to Slack Channel

We are going to use the following AWS services to achieve this alerting and monitoring system

  • Cloud Watch - To create an alarm when a certain threshold is met on a specific timeframe

  • SNS Topic - To trigger a notification when the alert is breached (or) cleared

  • AWS ChatOps - to integrate slack and create alert messages directly to the Slack channel

alb cloudwatch monitor slack

Creating AWS Chatbot and integration SNS topic and Slack Channel

As we have completed the first two requirements of our monitoring setup, the only remaining part is Slack integration with SNS topic using AWS Chatbot

In the AWS console, head to AWS Chatbot and click on Configure New Client

Once you click you would see two options, Choose slack and Configure

CloudWatch Slack

As you click the configure button, you would be redirected to a slack authorization screen

If you are not already logged into Slack in the same browser you would be asked to login

Otherwise, it would choose the Slack profile by default and show the following screen

aws chatbot integration slack

Now click on Allow.

Once you have authorized, you would be redirected to AWS and you can see a new Configured Clients with your Slack Organization name

AWS Chatbot slack

Now on this screen, click on the Configure new channel

You Need to fill in the following items

  • Configuration name - Some Name for your Slack channel configuration

  • Channel Type - Public/ Private

  • Name of the Channel where the alert should be sent ( browse and select)

  • Channel role - You can let it be the default and aws would create an IAM role

  • Guardrail policy - To prevent slack from connecting back to AWS and even if it does what permission it can have to the max. You can choose some minimal IAM policy ( read-only)

  • Notifications -> SNS Topic - You can choose the SNS topic where the chatbot would look for messages. Subscription model. You can choose the SNS topic we created in the previous section

Once filled with all these items click on the configure to move on.

Refer to the following image as a sample ( some values are not filled in the screenshot)

Now when you click on the configure after entering the necessary details, you would see the following screen

aws chatbot slack channel

You can see a success message bar on the top with a message You Successfully configured the Slack Channel

It would also instruct what next to be done.

Adding the AWS ChatBot App to the Slack Channel

Go to the Slack channel and add the AWS Chatbot app using Add apps from Channel's Details screen

In the Search bar type aws and choose the AWS Chatbot App and click on Add

You would see a message aws app was added to the Channel on the channel itself

Now whenever the CloudWatch alarm is transitioning to ALARM state you would be notified here on the Slack channel

ChatBot Slack Alert Sample

Conclusion

In this article, you have learnt how to configure AWS Chatbot to send Cloudwatch Alarms to Slack Channel step by step