AWS CloudWatch Slack Connection: Performance Alerts Simplified 101

on Amazon CloudWatch, Integration, Slack • May 20th, 2022 • Write for Hevo

cloudwatch slack - featured image

A monitoring system holds great importance when it comes to matured tech products and applications. Getting notified in a scenario where something goes wrong with the system helps in limiting operational losses and the time lost in recovering from the unpleasant situation. Therefore, alarms and performance alerts play a major role in the smooth functioning of any application or platform. If you are hosted on AWS, then CloudWatch is an impeccable tool to create triggers and alarms for specific scenarios. In this article, you will learn how to get these notifications from CloudWatch onto your Slack platform with CloudWatch Slack Integration. 

Let us start by briefly describing what is Slack and CloudWatch and then moving on to the steps for CloudWatch Slack Integration.

Table of Contents

What is Slack?

Slack is a widely used messaging platform for businesses and enterprises. The most basic purpose of this platform is to connect people to the information they are seeking. It is different from any other basic communication app for businesses. It is a unified platform for messaging, and sharing files, and has various tools that make day-to-day tasks seamless and more collaborative in nature. The two methods of chat in slack are the direct message (personal chat) and channels (for group chat).

The UI/UX is pretty simple as well. This is what it looks like:

Slack UI: cloudwatch slack - Hevo Data
Source: howtogeek.com

Simplify ETL Using Hevo’s No-Code Data Pipeline

Hevo Data, a Fully-managed Data Pipeline platform, can help you automate, simplify & enrich your data replication process in a few clicks. With Hevo’s wide variety of connectors and blazing-fast Data Pipelines, you can extract & load data from 100+ Data Sources straight into, Data Warehouses, or any Databases. To further streamline and prepare your data for analysis, you can process and enrich raw granular data using Hevo’s robust & built-in Transformation Layer without writing a single line of code!

GET STARTED WITH HEVO FOR FREE

Hevo is the fastest, easiest, and most reliable data replication platform that will save your engineering bandwidth and time multifold. Try our 14-day full access free trial today to experience an entirely automated hassle-free Data Replication!

What is CloudWatch?

CloudWatch is one tool that helps you monitor your stack end to end and uses alarms, events, and logs to automate actions. This helps in reducing the meantime to resolution and reduces the dependency on critical resources. CloudWatch provides data and insights for cloud, hybrid, and on-premise applications. Ultimately, CloudWatch helps businesses with:

  • Application Performance Optimization
  • Optimum Resource Utilization
  • Monitoring System-wide Operational Health

There is a provision for performing analysis on historical data to optimize cost, applications, and infrastructure resources by deriving real-time insights. The CloudWatch Container Insights helps businesses to monitor, troubleshoot, and alert their containerized applications and also microservices. It also allows DevOps engineers in identifying issues by summarizing compute utilization information. With this information, DevOps engineers are able to quickly isolate specific issues and resolve them within no time. 

What are Performance Alerts in CloudWatch?

A performance alert in CloudWatch, also known as alarms, performs one or many actions for a certain time period based on the value of a metric that is relative to a threshold. Now, what is a metric?

The basic metrics in CloudWatch are the functions that allow engineers to monitor how the entire system performs. These could be latency, invocations, errors, and concurrency. The possibility and probability of an engineer checking the metrics at the same time something goes wrong are very less. Therefore, configuring alarms or alerts upfront helps with smooth operations.

There are three alarm states:

  • OK: It means that the metric is located inside the defined threshold.
  • ALARM: It means the metric is located outside the defined threshold.
  • INSUFFICIENT_DATA: It means that the metric is not available but the alarm has already started, or the data is not enough for the metric to realize the state of the alarm.

How does CloudWatch Evaluate when to Change the Alarm State?

The answer is by specifying the below-mentioned settings:

  • Period: It enables you to evaluate the time duration of the metric to create an individual data point for an alarm.
  • Evaluation Period: It is the number of recently generated data points required to decide the state of the alarm.
  • Datapoints to Alarm: The number of data points that must be breached in order to cause the alarm to go in the ALARM state

How to Setup CloudWatch Slack Integration?

Here is a step by step guide for CloudWatch Slack Integration:

  • Step 1: Create an SNS Topic
  • Step 2: Create a Lambda Function
  • Step 3: Create a Slack Channel
  • Step 4: Create CloudWatch Alarms

What makes Hevo’s ETL Process Best-In-Class

Providing a high-quality ETL solution can be a difficult task if you have a large volume of data. Hevo’s automated, No-code platform empowers you with everything you need to have for a smooth data replication experience.

Check out what makes Hevo amazing:

  • Fully Managed: Hevo requires no management and maintenance as it is a fully automated platform.
  • Data Transformation: Hevo provides a simple interface to perfect, modify, and enrich the data you want to transfer.
  • Faster Insight Generation: Hevo offers near real-time data replication so you have access to real-time insight generation and faster decision making. 
  • Schema Management: Hevo can automatically detect the schema of the incoming data and map it to the destination schema.
  • Scalable Infrastructure: Hevo has in-built integrations for 100+ sources (with 40+ free sources) that can help you scale your data infrastructure as required.
  • Live Support: Hevo team is available round the clock to extend exceptional support to its customers through chat, email, and support calls.
Sign up here for a 14-day free trial!

Step 1: Create an SNS Topic

Under create topic option, assign the name “aws-notification” and click next step.

Create an SNS Topic: cloudwatch slack - Hevo Data
Source: enlear.academy

Keeping the rest of the things as default, click the create topic button.

Creating an SNS Topic: cloudwatch slack - Hevo Data
Source: enlear.academy

Step 2: Create a Lambda Function

  • Click create function under the Lambda service.
  • Select the author.
  • Assign the function name as “aws-notification-function”.
  • Select Runtime as Python 3.9.
  • Last but not the least, click Create Function
Create Lambda Function - cloudwatch slack - Hevo Data
Source: enlear.academy
  • Select lambda_function.py and add the code that is mentioned below:
cloudwatch slack - Hevo Data
Source: enlear.academy
  • Next, add the Slack App URL and Channel Name followed by saving the code inside AWS Lambda.
  • If the changes are not deployed then you cannot test the functions.
Create Lambda Function: cloudwatch slack - Hevo Data
Source: enlear.academy

Step 3: Create a Slack Channel

  • Next, you would have to create a Channel and an app inside Slack.
  • You can follow these steps to create a Slack App.
  • Activate Incoming Webhooks in the Slack App to connect with SNS
    • Click the “Add New Webhook to Workspace” button.
    • Copy the Webhook URL.
Create Slack Channel: cloudwatch slack - Hevo Data
Source: enlear.academy
  • Paste the previously copied webhooks URL to the lambda_function.py URL section and add the channel name
  • Here’s a sample: 
url = "https://hooks.slack.com/services/xxxxxxxxxxx/xxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxx" "channel": "aws-notifications",
  • Click the Test Button in the Lambda function and create a Test Event. Select the event template as “SNS Topic Notification”.
Create Slack Channel: cloudwatch slack - Hevo Data
Source: enlear.academy
  • Give the Event Name and click create button.
Create Slack Channel: cloudwatch slack - Hevo Data
Source: enlear.academy
  • Deploy changes by clicking the Deploy button.
Create Slack Channel: cloudwatch slack - Hevo Data
Source: enlear.academy
  • Click the Test button to see the following output. If you are getting this specific output it means that your function is working.
Create Slack Channel: cloudwatch slack - Hevo Data
Source: enlear.academy
  • You will also see the below message on your Slack Channel:
Receive message on Slack Channel: cloudwatch slack - Hevo Data
Source: enlear.academy
  • Next, add SNS as a trigger to the Lambda function. Under Trigger, select SNS as configuration and select SNS Topic name. Then, click Add button.
AWS notification function: cloudwatch slack - Hevo Data
Source: enlear.academy
  • Click publish message in SNS. After that, you can type anything in “Message body to send to the endpoint” and click publish message button.
Publish Message: cloudwatch slack - Hevo Data
Source: enlear.academy
  • Your latest message will also appear on the Slack Channel.
Message appears on slack channel: cloudwatch slack - Hevo Data
Source: enlear.academy

Step 4: Create CloudWatch Alarm

The Slack channel that you have created while CloudWatch Slack Integration will receive the CloudWatch alarms.

  • Create an Ubuntu 20.04 EC2 instance and install the below-mentioned package:
sudo apt-get install -y stress
  • After that create CloudWatch Alarm for previously created EC2. Select an SNS topic name.
Configure Action: cloudwatch slack - Hevo Data
Source: enlear.academy
  • Increase CPU usage in EC2 with the below-mentioned command
stress --cpu 2 --timeout 300s
  • After all this, you can finally see the latest alerts on the Slack channel. Hence the CloudWatch Slack Integration is successful!
AWS Notification: cloudwatch slack - Hevo Data
Source: enlear.academy

Conclusion

As this article comes to an end, you would now be able to get CloudWatch alarms on a Slack channel by following the steps for Cloudwatch Slack Integration. This kind of integration and automation make the lives of DevOps engineers much easier. Similarly, the Data Integration and Transformation enabled by Hevo also make the lives of Data Engineers and Analysts easier.

Hevo Data is a prizewinning ETL solution to help businesses export data from their sources into their desired Database/destination. Its No-code Data Pipeline provides you with a consistent and reliable solution to manage data transfer from 100+ Data Sources (including 40+ Free Sources) to a wide variety of desired destinations with a few simple clicks.

Hevo also allows the integration of data from non-native sources using Hevo’s in-built REST API & Webhooks Connector. You can then focus on your key business needs and perform insightful analysis using BI tools. 

Give Hevo a try and Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand. You may also have a look at the unbeatable pricing, which will assist you in selecting the best plan for your requirements.

We hope you found this article on CloudWatch Slack Integration helpful. Thanks for reading.

No Code Data Pipeline For Your Data Warehouse