Aws Sns Slack



If your company uses Slack and is looking for ways to easily monitor activities in its AWS Golden AMI Pipeline, you can use AWS native services to send messages into a Slack channel. This can give your teams better visibility into the approval process for the candidate AMIs that they submit, as opposed to handling this via email. As we all know, email messages can get lost, overlooked or dumped in spam folders, which doesn’t happen with Slack messages. Moreover, Slack channels can have multiple subscribers so a single message can be seen by multiple people or other bots. Handling approval requests within a Slack channel also simplifies the management of the process.

Read on for a detailed, step-by-step explanation.

Getting Started

Lab warning Using AWS Lambda with Amazon CloudWatch and SNS to Implement a Slack Chat Bot. In this lab you will build a chat bot for Slack, using a Lambda blueprint. Chat bots have the ability to interact with teams and users, respond to commands, and post notifications, giving all conversation participants visibility into team activities. AWS EC2 monitoring with Cloudwatch, SNS, Lambda, and Slack By default, when managing a large number of EC2 instances, you don't get a lot of visibility into how your instances are behaving. Any monitoring beyond what you get in the console needs to be configured and set up by the AWS user using services like Cloudwatch or Cloudtrail, etc.

Slack configuration

You must first configure Slack to receive messages from the Golden AMI Pipeline. To do this you need to create a new channel – or choose an existing channel — to receive the notifications: For example “#aws-gap-updates”. Next you will configure a Slack app for “Incoming WebHooks”. This can be done by logging into your Slack account via a web browser and navigating to your account’s Slack App Directory and typing in “Incoming WebHooks” into the search bar.

AWS Lambda function for forwarding SNS notifications to Slack GitHub Instantly share code, notes, and snippets. If you want to use SNS as a decoupling layer, you'll need to add a lambda into the system, which can handle the confirmation process. Lambda - webhook - SNS - Lambda - webhook - Slack Confirming AWS SNS Topic Subscription for Slack Webhook has some more information about this. To configure a Slack client. Open the AWS Chatbot console at. Under Configure a chat client, choose Slack, then choose Configure client. From the dropdown list at the top right, choose the Slack workspace that you want to use with AWS Chatbot.

Select “Incoming WebHooks” and then click “Add Configuration” on the next screen.

On the app configuration screen, choose a channel for the WebHook and click “Add Incoming WebHooks Integration.”

At this point, you will see the configuration information for your Slack App Incoming WebHooks. Scroll past the example data down to Webhook URL. This is the URL you will use to send messages to this Webhook. Copy this unique link so it is easy to retrieve, as you will need it later when setting up a Lambda function to send messages received from the Golden AMI Pipeline SNS topic.

Aws Sns Slack

AWS Lambda Function

Creation

There are many examples of Lambda functions for processing events and executing some code, so I will not cover that here. The basics of the function is that it needs to intake a message from the SNS topic and then send that message to the desired location. For this to happen, the Lambda function will need four pieces of required information and one optional configuration item.

Slack information for Lambda:

  1. Channel
  2. Username
  3. Text
  4. Icon Emoji (optional)
  5. Path

The Channel setting will direct the message to the channel configured in the Slack Webhook configuration and the Path will be the Slack Webhook URL from above. The Username is what will appear in the Slack channel as the sender of the message, and the text will either be the raw SNS notification or the specific data you extract from the message. The Icon Emoji can be used to specify the icon used for the sender of the Slack message. You can use any of the standard Slack emojis or a custom emoji of your choosing.

Configure

After creating your AWS Lambda function to process SNS notifications and send them to your designated Slack channel, you will need to subscribe the Lambda function to the SNS topic. Information on subscribing the Lambda function to a SNS topic can be found here.

Test

Make sure to test and validate both the Lambda function and the SNS subscription to send messages from the AWS Golden AMI Pipeline. You can test fire the Lambda function with an example SNS message to validate functionality and then trigger a test SNS message from the SNS topic to verify the subscription and desired functionality.

Aws sns slack certification

Final Thoughts

Once you have the candidate AMI approval messages being sent to the Slack Channel, you can look to expand what messages or SNS topics get sent. This can include the creation of other SNS topics for specific functions or triggered actions and reusing the configured Lambda function to send other messages. One example would be to expand the Golden AMI Pipeline’s steps to include additional logging via SNS messages sent to your Slack channel. You could also look at building out a Slack bot for submission of candidate AMIs to the Golden AMI Pipeline. There is a great GitHub example at https://github.com/esanchezm/amazon-cloudwatch-to-slack/ if you would like to explore these scenarios further.

(Sean Nicholson is a Security Solution Architect for Cloud Security at Qualys)

January 1, 2016 | Comments(13) |

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.

  • Create an Incoming Webhook in slack.
  • Create a Lambda function which sends the notification to the slack.
  • Make the Lambda function subscribe to the SNS Topic.
  • Create an Alarm on the EC2 instance.

Prerequisites:

  • You must have a slack account
  • A running EC2 instance

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

Step 2: Click on your team name as below

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

Aws Sns To Slack

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

Step 5: Install the app in your respective Team.

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

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.

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

Aws sns slack terraform

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.

Step 2: Skip the Blueprint

Step 3: Insert Name and Description for 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 other fields as it is and click on next.

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

Aws Sns トピック Slack

Aws

Aws Cloudwatch Sns Slack

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.

Step 2: Provide the Information as shown below.

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

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

Aws sns slack interview

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.

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.

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

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:

  • Lambda Function
  • SNS Topic
  • EC2 Alarm