{"id":4087,"date":"2016-01-01T00:00:10","date_gmt":"2016-01-01T00:00:10","guid":{"rendered":"http:\/\/blog.cloudthat.com\/?p=4087"},"modified":"2024-06-25T11:13:03","modified_gmt":"2024-06-25T11:13:03","slug":"integrating-aws-lambda-with-slack","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/integrating-aws-lambda-with-slack","title":{"rendered":"Integrating AWS Lambda with Slack"},"content":{"rendered":"<p>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.<\/p>\n<ul>\n<li>Create an Incoming Webhook in slack.<\/li>\n<li>Create a Lambda function which sends the notification to the slack.<\/li>\n<li>Make the Lambda function subscribe to the SNS Topic.<\/li>\n<li>Create an Alarm on the EC2 instance.<\/li>\n<\/ul>\n<p><strong>Prerequisites: <\/strong><\/p>\n<ul>\n<li>You must have a slack account<\/li>\n<li>A running EC2 instance<\/li>\n<\/ul>\n<p><strong>Step by step process to integrate Lambda with Slack:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h3>Task 1: Create an Incoming Webhook in slack.<\/h3>\n<p style=\"padding-left: 30px;\">Step 1: Go to your slack application where you might be able to see below scenario<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/A1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4089 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/A1.png\" alt=\"A1\" width=\"1366\" height=\"639\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 2: Click on your team name as below<\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4088 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/127.png\" alt=\"1\" width=\"1366\" height=\"639\" \/><\/p>\n<p style=\"padding-left: 30px;\">Step 3: You will find a popup Menu as shown below and click on App and Custom Integration<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/214.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4090 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/214.png\" alt=\"2\" width=\"253\" height=\"529\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 4: You will find the application site of Slack. Type &#8220;incoming\u201d in the search box and select the Incoming Webhooks.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/315.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4091 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/315.png\" alt=\"3\" width=\"1359\" height=\"626\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 5: Install the app in your respective Team.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/45.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4092 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/45.png\" alt=\"4\" width=\"1348\" height=\"644\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 6: Select the channel and click on Add Incoming Webhook<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/66.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4093 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/66.png\" alt=\"6\" width=\"1302\" height=\"564\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 7: So the Incoming Webhook is being created.<\/p>\n<p style=\"padding-left: 30px;\">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.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/76.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4094 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/76.png\" alt=\"7\" width=\"1095\" height=\"643\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 9: We will use the Webhook URL in Lambda Function<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>Task 2: Create a Lambda function which sends the notification to the slack.<\/h3>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 1: Go to AWS Lambda Console and click on Get Started Now.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/86.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4095 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/86.png\" alt=\"8\" width=\"823\" height=\"373\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 2: Skip the Blueprint<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/A2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4096 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/A2.png\" alt=\"A2\" width=\"932\" height=\"575\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 3: Insert Name and Description for your Lambda function.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/A3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4097 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/A3.png\" alt=\"A3\" width=\"945\" height=\"542\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 4: Go to the link <a href=\"https:\/\/s3-us-west-2.amazonaws.com\/cloudthat.training\/Lambda-slack-integration\/lambd-slack-Integraion.dat\">https:\/\/s3-us-west-2.amazonaws.com\/cloudthat.training\/Lambda-slack-integration\/lambd-slack-Integraion.dat<\/a> and copy the code in the editor.<\/p>\n<p style=\"padding-left: 30px;\">Step 5: Create a basic Execution role for lambda<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/97.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4098 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/97.png\" alt=\"9\" width=\"992\" height=\"445\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 6: Leave other fields as it is and click on next.<\/p>\n<p style=\"padding-left: 30px;\">Step 7: Review the function and click on Create Function.<\/p>\n<p style=\"padding-left: 30px;\">Step 8: Your function is created and now put your webhook URL as \u201cslack_url\u201d\u2019s value.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>Task 3: Make the Lambda function subscribe to the SNS Topic.<\/h3>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 1: Go to SNS and click on Create Topic.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/137.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4099 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/137.png\" alt=\"13\" width=\"1118\" height=\"484\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 2: Provide the Information as shown below.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/145.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4100 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/145.png\" alt=\"14\" width=\"897\" height=\"394\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 3: Now we will create a subscription for the lambda function. Click on Create Subscription.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/152.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4101 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/152.png\" alt=\"15\" width=\"1100\" height=\"439\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 4: Select Lambda Function as protocol and Endpoint as your lambda function ARN.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/5-Tech-Areas-that-are-Changed-Forever-after-AWS-reInvent-20162.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4102 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/5-Tech-Areas-that-are-Changed-Forever-after-AWS-reInvent-20162.png\" alt=\"16\" width=\"886\" height=\"383\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 5: Your Function is now read to get notifications from SNS.<\/p>\n<p style=\"padding-left: 30px;\">Step 6: You can Test, click on Action and select Configure test event.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/172.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4103 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/172.png\" alt=\"17\" width=\"866\" height=\"427\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 7: You can get a sample event from following link <a href=\"https:\/\/s3-us-west-2.amazonaws.com\/cloudthat.training\/Lambda-slack-integration\/test-lambda.dat\">https:\/\/s3-us-west-2.amazonaws.com\/cloudthat.training\/Lambda-slack-integration\/test-lambda.dat<\/a> and you can check Message in slack.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>Task 4: Create an Alarm on the EC2 instance.<\/h3>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">Step 1: Go to your EC2 Instance and create an alarm by clicking on \u00a0Alarm.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1110.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4104 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/1110.png\" alt=\"11\" width=\"1151\" height=\"201\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 2: The window will pop up and provide the information as shown below and click on \u201cCreate Alarm\u201d.<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/128.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"border-img-2 alignnone wp-image-4105 size-full\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/128.png\" alt=\"12\" width=\"1018\" height=\"517\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\">Step 3: Your alarm is created.<\/p>\n<p style=\"padding-left: 30px;\">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%.<\/p>\n<p style=\"padding-left: 30px;\">Step 5: Now if your CPU will go beyond threshold value you will get a Message in Slack.<\/p>\n<p>&nbsp;<\/p>\n<p>So we have configured a lambda function to send Cloudwatch alerts\u00a0to 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 <a title=\"forum.cloudthat.com\" href=\"https:\/\/forum.cloudthat.com\" target=\"_blank\" rel=\"noopener\">forum.clodthat.com<\/a>\u00a0or you can post a comment.<\/p>\n<p>Thank you.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Cleanup:<\/strong><\/p>\n<ul>\n<li>Lambda Function<\/li>\n<li>SNS Topic<\/li>\n<li>EC2 Alarm<\/li>\n<\/ul>\n","protected":false},"author":219,"featured_media":0,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3804,3606,3607,3665],"user_email":"prarthitm@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/4087"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/219"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=4087"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/4087\/revisions"}],"predecessor-version":[{"id":45992,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/4087\/revisions\/45992"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=4087"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=4087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}