No Widgets found in the Sidebar

This blog will show you how to integrate Lambda and slack. You’ll receive important notifications in the slack channel. The following task will be accomplished.
Incoming webhook in slack
Create a Lambda function that sends the notification directly to the slack.
Subscribe to the SNS Topic by making the Lambda function available.
Set up an alarm on the EC2 instance
Prerequisites:
You need to have a slack bank account
A running EC2 instance
Step by step guide to integrating Lambda with Slack

Task 1: Create an Incoming webhook in slack
Step 1: Open your slack app and look at the scenario below

Step 2: Click below on the team name

Step 3: Click on App and Custom Integration to open a popup menu.

Step 4: Search for the Slack application site. Type “incoming” into the search box, and then select the Incoming Webhooks option.

Step 5: Install the app within your team.

Step 6: Select the channel, then click on Add Incoming Webhook

Step 7: Now the Incoming Webhook has been created.
Step 8: You only need a Webhook URL, which you can find below. You can customize name and image of sender and save the setting.

Step 9: We will use Webhook URL in Lambda Function

Task 2: Create a Lambda function that sends the notification email to the slack.

Step 1: Visit AWS Lambda Console, and click on Get Started Right Now.

Step 2: Skip the Blueprint

Step 3: Enter Name and Description of your Lambda function.

Step 4: Go to the link https://s3-us-west-2.amazonaws.com/cloudthat.training/Lambda-slack-integration/lambd-slack-Integraion.dat and copy the code in the editor.
Step 5: Create a basic Execution Role for lambda

Step 6: Leave all other fields blank and click on Next.
Step 7: Go through the function and click on Create Function.
Step 8: Create your function and then set the value of your webhook URL to “slack_url”.

Task 3: Subscribe the Lambda function to the SNS Topic.

Step 1: Click on Create Topic in SNS.

Step 2: Fill in the information as shown below.

Step 3: Next, we will create a subscription to the lambda function. Click on Create Subscription.

Step 4: Choose Lambda Function to be your protocol and Endpoint to be your lambda function’s ARN.

Step 5: Now your Function is read and you will receive notifications from SNS.
Step 6: Click on Action to test and choose Configure test event.

Step 7: You can get a sample event from following link https://s3-us-west-2.amazonaws.com/cloudthat.training/Lambda-slack-integration/test-lambda.dat and you can check Message in slack.

Task 4: Create an alarm on the EC2 instance

Step 1: Click on Alarm to create an alarm at your EC2 Instance.

Step 2: Click on “Create Alarm” to activate the window.

Step 3: Your alarm has been set.
Step 4: We have given the Average CPU Utilization at 85 %, but you can also put it at 1% if you need an alarm quickly.
Step 5: If your CPU goes above threshold value, you will receive a message in Slack.

We have now set up a lambda function that sends Cloudwatch alerts through SNS to Slack. You can also post comments or ask questions to the forum.clodthat.com.
We are grateful.

Cleanup:
Lambda Function
SNS Topic
EC2 Alarm

By Delilah