API, AWS, Cloud Computing, Tutorials

4 Mins Read

Integrating AWS Lambda with Slack

In this blog, we are going to integrate Lambda with slack to receive important notification in the slack channel. We will accomplish the following task.

Prerequisites:

Step by step process to integrate Lambda with Slack:

 

Task 1: Create an Incoming Webhook in slack.

Step 1: Go to your slack application where you might be able to see below scenario

A1

Step 2: Click on your team name as below

1

Step 3: You will find a popup Menu as shown below and click on App and Custom Integration

2

Step 4: You will find the application site of Slack. Type “incoming” in the search box and select the Incoming Webhooks.

 

3

Step 5: Install the app in your respective Team.

 

4

 

Step 6: Select the channel and click on Add Incoming Webhook

 

6

 

Step 7: So the Incoming Webhook is being created.

Step 8: All you need is a Webhook URL that you can find as below and you can also customize name and image of the sender and save the setting.

 

7

 

Step 9: We will use the Webhook URL in Lambda Function

 

 

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

 

Step 1: Go to AWS Lambda Console and click on Get Started Now.

 

8

 

Step 2: Skip the Blueprint

 

A2

Step 3: Insert Name and Description for your Lambda function.

 

A3

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

 

9

Step 6: Leave other fields as it is and click on next.

Step 7: Review the function and click on Create Function.

Step 8: Your function is created and now put your webhook URL as “slack_url”’s value.

 

 

Task 3: Make the Lambda function subscribe to the SNS Topic.

 

Step 1: Go to SNS and click on Create Topic.

13

 

Step 2: Provide the Information as shown below.

 

14

Step 3: Now we will create a subscription for the lambda function. Click on Create Subscription.

15

Step 4: Select Lambda Function as protocol and Endpoint as your lambda function ARN.

 

16

 

Step 5: Your Function is now read to get notifications from SNS.

Step 6: You can Test, click on Action and select Configure test event.

 

17

 

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: Go to your EC2 Instance and create an alarm by clicking on  Alarm.

 

11

Step 2: The window will pop up and provide the information as shown below and click on “Create Alarm”.

12

Step 3: Your alarm is created.

Step 4: We have provided the Average CPU Utilization to 85 % but if you want to get an alarm quickly, you can put it as 1%.

Step 5: Now if your CPU will go beyond threshold value you will get a Message in Slack.

 

So we have configured a lambda function to send Cloudwatch alerts to Slack application.We can send any alerts which are sent through SNS to slack.We can also send a custom message by changing the lambda code.If you have any queries regarding this blog you can ask the questions to the forum.clodthat.com or you can post a comment.

Thank you.

 

Cleanup:

Voiced by Amazon Polly

WRITTEN BY CloudThat

CloudThat is a leading provider of cloud training and consulting services, empowering individuals and organizations to leverage the full potential of cloud computing. With a commitment to delivering cutting-edge expertise, CloudThat equips professionals with the skills needed to thrive in the digital era.

SHARE

Comments

  1. Cognex

    Feb 3, 2021

    Reply

    Valuable Please Keep Updating Us

    • Anusha Shanbhag

      Feb 18, 2021

      Reply

      Thank you. Definitely.

  2. Cognex

    Jan 6, 2021

    Reply

    Thanks For Sharing The Information The Information shared Is Very Valuable Please Keep Updating Us.

  3. saikumar

    May 21, 2019

    Reply

    I can’t open code from the cloudthat.training/Lambda-slack-integration/lambd-slack-Integraion.dat can anyone help

  4. saikumar

    May 21, 2019

    Reply

    I can’t open code from the cloudthat.training/Lambda-slack-integration/lambd-slack-Integraion.dat

  5. peter

    Jun 5, 2018

    Reply

    Could you please share the code. The link is in accessible.

  6. shufil

    Jan 2, 2018

    Reply

    i have getting issue while we creating subscription in SNS, it not got creating subscription

  7. Max

    Jul 6, 2017

    Reply

    Is it possible to do the same but check send ping or check https status and notify us via slack. Seems like you’ll get notified only if cpu gets over 85% here. But what if you want to monitor a website on a specific server?

  8. VenkatAithagoni

    Feb 16, 2017

    Reply

    Thanks, it worked. awesome info.

  9. Vic

    Jan 6, 2017

    Reply

    It is very easy and understanding, worked. very appreciated for sharing.

  10. meathouse

    Jul 8, 2016

    Reply

    Thanks! Worked perfectly. I followed a few online demos and this was the only one that worked. Each piece is broken down well. Huge time saver. Thanks again.

  11. Rebecca

    May 3, 2016

    Reply

    Very Helpful!!

  12. sagar

    Jan 23, 2016

    Reply

    very useful. thank you.

  13. Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!