AWS SNS is a pub/sub messaging service that delivers messages from a publisher to a subscriber. Publishers send messages to a SNS topic, which stores those messages in a queue. A list of AWS services capable of publishing to a SNS topic can be found here. Clients can subscribe to a SNS topic and receive messages from that topic using a supported endpoint like AWS Lambda or an HTTP webhook. A list of message subscribers can be found here.
To push messages to Slack, we will use the HTTP webhook endpoints for a SNS topic. When used in conjunction with a Slack webhook, SNS can be used to publish alerts, logs or other information about your AWS resources directly to a Slack channel, which makes this information easily accessible to your entire team.
Process:
When you create a webhook trigger for a Slack workflow, you can specify variables that pull values from the JSON request body. In our case, we’re pulling the “Message” and “SubscribeURL” properties from the request body. When we first create the HTTPS subscription, SNS sends a confirmation request to the endpoint with the following format:
We use the “SubscribeURL” variable to capture the “SubscribeURL” property from the request body so that we can use it to confirm the subscription. Once our subscription is confirmed, we can remove the “SubscribeURL '' variable, as that is only sent with the confirmation request; normal SNS messages do not have that property. Anytime a message is published to the topic, SNS will send a request to the webhook with the following format:
Our “Message” variable grabs the value of the “Message” property from the SNS request and posts it to our Slack channel. If we want to grab other properties from this request, we just need to add that property name to workflow trigger variables and then insert the variable into the message text in the send message step.
Once the SNS to Slack pipeline is set up, you can send information from any SNS-supported AWS services to your Slack channel by having those services publish messages to your SNS topic. This can be used to send alerts, logs, or other messages to your team’s Slack channel, which gives all of your developers quick and easy access to this information. However, it is important to ensure that you are not including sensitive information in your SNS messages, as anyone who is able to access your developer Slack channel will be able to view this information.
Ryan Shendler is an associate software engineer at Jahnel Group, Inc., a custom software development firm based in Schenectady, NY. Jahnel Group is a consulting firm that specializes in helping companies leverage technology to improve their business operations. We provide end-to-end strategic consulting and deployment services, helping companies optimize their operations and reduce costs through the use of technology. Jahnel Group is an Advanced Tier AWS Services Partner, with expertise in AWS Lambdas, Amazon API Gateway, Amazon DynamoDB, and other AWS services.