Are you using Amazon SNS (Amazon Simple Notification Service) for your business? Are you looking out for a solution to integrate Amazon SNS to Slack? If yes, then you are in the right spot.
Slack is a digital platform that links companies with the tools and people they interact with daily. As a result, integrating AWS SNS to Slack will make it simple to engage with business teams via dedicated channels and direct messaging. However, Amazon SNS does not support integrating directly with a third-party application. SNS requires Webhooks to deliver messages to third-party applications such as Slack. This article provides detailed steps to connect your AWS SNS to Slack from scratch using Slack Incoming Webhooks.
In this article, you will get an overview of Amazon SNS and Slack. In addition, you will explore their key features. Furthermore, you’ll learn to generate a Slack Incoming Webhook URL and steps to connect your SNS to Slack. So, let’s get started with the SNS Slack Integration for a seamless workflow.
What is Amazon SNS?
Amazon SNS (Amazon Simple Notification Service) is a managed service that delivers messages from publishers to subscribers (also known as producers and consumers). It automates the process of delivering notifications to the associated subscribers. It pushes and delivers messages using the publish/subscribe model. The data is stored across different availability zones to prevent data loss.
SNS is used to simplify the messaging architecture by offloading message filtering and message routing logic from subscribers and publishers, respectively. Rather than receiving all of the messages from the topic, SNS transmits only the messages that are of interest to the subscriber.
You can send direct messages to your customers using Amazon SNS. It allows users to send SMS text messages to 200+ countries, offers mobile push alerts to Amazon, Android, Apple, Baidu, and Microsoft devices, and supports email notifications.
Hevo is a no-code data pipeline platform that supports Asana and Slack as Sources. Its intuitive User interface ensures that data integration is simple and that the pipeline is set up in minutes.
- With its robust transformation capabilities, Hevo ensures that your data is always ready for analysis.
- Hevo’s cost-efficient pricing makes sure you only pay for what you use.
- Its fault-tolerant architecture ensures your data is always secure and there is no data loss
Try Hevo for free today to experience seamless migration of your data!
Get Started with Hevo for Free
Key Features of AWS SNS
Amazon SNS offers the following remarkable features:
- Message Ordering: Amazon SNS FIFO topics function in conjunction with Amazon SQS FIFO queues to ensure that messages are delivered in a tight sequence and processed only once. This ensures accuracy and consistency.
- Message Fanout: When a message is sent to a topic, it is replicated and sent to numerous endpoints. Asynchronous event notifications are generated by Fanout, allowing for parallel processing.
- Message Encryption: Amazon SNS supports encrypted topics, which protect your messages from unwanted and unknown access. Server-Side Encryption safeguards the message contents saved in Amazon SNS Topics by leveraging AWS KMS Encryption Keys.
- Message Filtering: Each subscriber receives every message published to the Topic by default. A subscriber can assign a Filter Policy to the Topic subscription in order to receive a subset of the messages. The message is delivered to the subscribed endpoint when the incoming message attributes match the Filter Policy attributes. Otherwise, the message is discarded.
- AWS Integrations: Amazon SNS allows users to send notifications to Amazon Simple Storage Service (Amazon S3) buckets, Amazon Redshift tables, and other Archiving and Analytics endpoints. Further in this article, you will learn how to connect SNS to Slack using Webhooks and Amazon Lambda.
- Message Archiving & Analytics: Amazon SNS allows the user to push notifications to additional Archiving and Analytics endpoints such as Amazon Simple Storage Service (Amazon S3) buckets, Amazon Redshift tables, and more.
Want to explore more about Amazon SNS? Refer to the official website.
What is Slack?
Slack is a cloud-based application developed in the United States that helps organizations keep their teams and employees connected. It offers Chat Rooms, Private Chat, and Direct Messages among other features.
Slack’s high-performance API makes it compatible with a wide range of applications. It has mobile applications for iOS and Android, as well as a web browser and desktop clients for macOS, Windows, and Linux. It can be synchronized with external applications like Google Drive, Calendar, and others.
Key Features of Slack
Slack is popular among many companies due to its amazing features. Some of the key features of Slack are:
- Messaging: Slack’s messaging capability is its most significant feature. Messages can be sent and received in real-time through an intriguing chat display. You can engage with people directly or via channels and threads.
- File-Sharing: Slack’s file-sharing capability makes it simple to exchange files, images, videos, etc. Documents and files up to 1GB can be uploaded to Slack using the paperclip symbol in the text box.
- Extensive Integrations: More than 1500 integration applications can be synchronized with Slack for your access. However, if you use the free plan, you can only integrate 10 apps at a time. You’ll learn more about integrating SNS to Slack in this article ahead.
What Are Slack Incoming Webhooks?
A Webhook, also known as a Web Callback or HTTP PUSH API, is a process that allows one application to send real-time data to another. You won’t have to poll for data as frequently as with typical APIs to get real-time results. As a result, Webhooks become substantially more efficient for both the provider and the consumer.
Slack Incoming Webhooks are a quick and easy method to get messages from applications into Slack. When you create an Incoming Webhook, you’ll be given a unique URL to which you can send a JSON payload including the message text and some other details. To make the messages stand out, you can use the standard formatting and style blocks with Incoming Webhooks. Later in this article, you will learn about the steps required to connect AWS SNS to Slack.
How to Create a Slack Incoming Webhook URL?
Further in this article, you will require a Slack Incoming Webhook URL to connect your AWS SNS to Slack. Follow the steps below to Create a Slack Incoming Webhook URL from scratch:
Step 1: The first step involved in connecting SNS to Slack requires you to create a Slack App. You can get started by taking a look at Slack API: Applications.
Step 2: Enable Incoming Webhooks for connecting SNS to Slack. To do so, go to Settings → Incoming Webhooks → Activate Incoming Webhooks. Your page will get refreshed.
Step 3: Create an Incoming Webhook by clicking on Add New Webhook to Workspace.
Step 4: Pick your desired Channel to post your messages from SNS to Slack and click on Authorize.
Step 5: You’ll be redirected to your app settings, where you should now notice a new entry under the Webhook URLs for your Workspace section, with a Webhook URL that looks like this:
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXX
Copy this URL and keep it securely. This will come in handy while connecting AWS SNS to Slack.
If you want to generate Incoming Webhook URLs programmatically, you can refer to Incoming Webhooks | Slack.
Steps to Integrate AWS SNS to Slack
Now that you have gained a basic understanding of Amazon SNS and Slack, let’s learn how to send messages from AWS SNS to Slack using Webhooks.
Amazon SNS can be used to send notifications to HTTP(S) endpoints such as Webhook URLs. When validating the HTTP(S) subscription, certain Webhooks such as Slack Incoming Webhooks need JSON key-value pairs, which Amazon SNS does not support.
A JSON request with a message string corresponding to a “text” key is required by the Incoming Slack Webhooks. Hence, here you will use an AWS Lambda function to modify the Amazon SNS message body JSON document for the webhook endpoint to process.
Follow the steps below to get started with SNS to Slack Integration:
Integrate Slack to Amazon S3
Integrate Webhooks to Redshift
Integrate Slack to PostgreSQL
Step 1: Create an SNS Topic
You must first establish an SNS Topic before you can begin setting up SNS to Slack Integration. To do so, follow the instructions below:
- Log in to your Amazon SNS Console.
- Navigate to the sidebar menu and select the Topics.
- Now, click on the Create Topic button as shown below.
- Next, specify a unique name for your SNS Topic. Once done, click on the Create Topic.
Refer to Creating an Amazon SNS topic – Amazon Simple Notification Service to learn more.
Step 2: Create a Lambda Function
You now must develop a Lambda Function to complete the second phase of the SNS to Slack Integration process. To do so, follow the steps below:
- Go to the Lambda Console.
- To create a new Lambda function, go to the Functions tab and select the Create Function button as shown below.
- Give your function a unique name and select the language in which you seek to build it.
- Click Create Function once you’ve finished filling out the appropriate fields.
- Once you’ve successfully constructed the Lambda Function, you’ll need to add some custom code to deliver the message to the destination. To send custom messages to a Slack channel, use the sample code provided below.
Note: In the below code, replace the https://hooks.slack.com/services/xxxxxxx and #CHANNEL_NAME with the Slack Incoming Webhook URL and destination Slack channel name respectively.
#!/usr/bin/python3.6
import urllib3
import json
http = urllib3.PoolManager()
def lambda_handler(event, context):
url = "https://hooks.slack.com/services/xxxxxxx"
msg = {
"channel": "#CHANNEL_NAME",
"username": "WEBHOOK_USERNAME",
"text": event['Records'][0]['Sns']['Message'],
"icon_emoji": ""
}
encoded_msg = json.dumps(msg).encode('utf-8')
resp = http.request('POST',url, body=encoded_msg)
print({
"message": event['Records'][0]['Sns']['Message'],
"status_code": resp.status,
"response": resp.data
})
Step 3: Test the Lambda Function
After you’ve added the custom code to your Lambda Function, use Lambda Console to test it and set up AWS SNS to Slack using Webhooks. Follow the steps below to test your integration:
- Click the Save button in the top right to save the Function code.
- Next, click the Test button.
- Select Amazon SNS Topic Notification in the Event Template area and give the event a unique name.
- Now, click the Create button once you’ve completed all of the necessary fields.
- When the test event is over, go to the Details area by clicking the Test button again.
Note: If the response code is 200, the Webhook has accepted the message and sent it to the appropriate channel and the SNS to Slack connection is complete. If the test fails with a 4xx status code, double-check the Webhook URL and make sure the key-value pair is accurate and recognized by the destination webhook. A 4xx status code depicts that there is some error in the SNS to Slack connection.
Step 4: Add an SNS Topic trigger to the Lambda Function
Once you’ve sent a message from SNS to Slack Webhook as a test in the Lambda console, you should subscribe your Lambda function to the SNS Topic. To do so, go to the Lambda console and create an SNS topic trigger by following the steps below:
- Go to the Lambda console Functions page and choose your function.
- Now, navigate to Designer → Add Trigger → Select a Trigger → , and choose SNS.
- Next, choose the SNS topic that you created earlier and select the Enable Trigger check box.
- Finally, select Add.
Great Job! You have successfully connected your Amazon SNS to Slack. Now, your messages published to your SNS topic can be passed to your function, which then forwards them to your Slack Incoming Webhook.
This is how you can connect SNS to Slack in a seamless fashion.
Understanding the JSON Format of Amazon SNS Notification
When Amazon SNS delivers a notification to a subscribed HTTP or HTTPS endpoint, the POST message comprises a JSON document containing the following name-value pairs in the message body:
Key | Value Description |
Message | The Message value is specified when the notification is published to the topic. |
MessageId | Each message published has its own Universally Unique Identifier. |
Signature | It is a Base64-encoded SHA1withRSA signature of the Message, MessageId, Type, Timestamp, and TopicArn values. |
SignatureVersion | It specifies the Amazon SNS signature version used. |
SigningCertURL | Specifies the certificate’s URL used to sign the message. |
Subject | It specifies the Subject parameter when the notification was published to the topic. |
Timestamp | It specifies the time (GMT) when the notification was published. |
TopicArn | It provides the Amazon Resource Name (ARN) of the topic to which this message was sent. |
Type | It specifies the type of message. For example for notification, the type is “Notification”. |
UnsubscribeURL | You can unsubscribe the endpoint from the topic using this URL. When you go to this URL, Amazon SNS unsubscribes the endpoint and no longer sends notifications to it. |
An example of an SNS Notification message to an HTTP endpoint is shown below:
You can also take a look at the key differences between SNS vs SQS to get a detailed understanding of how SNS works.
Other Destinations that can be Configured
Email
Set up Amazon SNS to send notifications to email by creating an email subscription. Once confirmed, you’ll start receiving notifications directly in your inbox.
Webhook
Amazon SNS can forward messages to a webhook endpoint via HTTP/HTTPS. Create a subscription and confirm it to start receiving notifications.
OpsGenie
Integrate Amazon SNS with OpsGenie to forward notifications and manage alerts effectively. For detailed steps, refer to OpsGenie’s integration guide.
Conclusion
In a nutshell, you gained a basic understanding of Amazon SNS and Slack. You learned the steps to connect SNS to Slack using the Slack Incoming Webhook. You also explored the format of the JSON body along with the SNS to Slack connection for the Amazon SNS Notification.
However, businesses today are confronted with more diverse and sophisticated data sets than they have ever been before. As a result, organizations can no longer manage their data only through simple ETL processes. To stay competitive, most businesses now employ a range of automatic ETL solutions. This is where a simple solution like Hevo comes in handy!
Try Hevo and see the magic for yourself. Sign up for a free 14-day trial to streamline your data integration process. You may examine Hevo’s pricing plans and decide on the best plan for your business needs.
Frequently Asked Questions
1. What is Amazon SNS used for?
Amazon SNS is a messaging service that allows applications and systems to send notifications to subscribers via various channels like email, SMS, and HTTP endpoints.
2. How do Slack Incoming Webhooks work?
Slack Incoming Webhooks enable applications to send messages directly to Slack channels using a unique URL, making it easy to post automated updates.
3. Can AWS SNS send notifications to Slack?
Yes, AWS SNS can send notifications to Slack by using a Lambda function to process messages and forward them to a Slack Incoming Webhook URL.
Shubhnoor is a data analyst with a proven track record of translating data insights into actionable marketing strategies. She leverages her expertise in market research and product development, honed through experience across diverse industries and at Hevo Data. Currently pursuing a Master of Management in Artificial Intelligence, Shubhnoor is a dedicated learner who stays at the forefront of data-driven marketing trends. Her data-backed content empowers readers to make informed decisions and achieve real-world results.