Setting up SNS Slack Integration using Webhooks: 3 Simple Steps

on Amazon SNS, Slack, Webhook • May 10th, 2022 • Write for Hevo

SNS Slack

If you have an AWS account, you can leverage Amazon’s Simple Notification Service (SNS) to publish and deliver notifications about Application Security events to subscribers. Amazon SNS does not support direct integrations with third-party applications, instead, it requires Webhooks to deliver SNS messages to third-party applications. Slack is one of the most widely used workspace communication platforms. When you use both of these solutions together, you may be able to strengthen customer relationships while also streamlining communication across your core organizational units.

This blog introduces you to Amazon SNS and Slack along with the key features that they offer. This article will also provide you with a step-by-step guide on how to set up SNS Slack Integration using webhooks. Read along to learn more about SNS Slack Integration!

Table of Contents

Prerequisites

  • An active AWS account.
  • An active Slack account.

What is Amazon SNS?

Amazon SNS Logo
Image Source

Amazon Simple Notification Service (SNS) is a Cloud Service that coordinates the delivery of push notifications from software applications to subscribed Endpoints and Clients. To prevent message loss, all messages published to Amazon SNS are warehoused across multiple availability zones.

Amazon SNS enables users to push messages to Windows, Google, Apple, and a few more Internet-connected smart devices by using an Application Programming Interface (API) or the AWS Management Console. Once a message is published to the service, it can be sent to multiple recipients. Service users can also utilize a single publish request to send direct messages to multiple devices or a single subscriber. To get started with Amazon SNS, developers must first create a Topic, which serves as an entry point for subscribers who want to receive notifications about a specific subject. When developers have an update for subscribers, they publish a message to a topic, and Amazon SNS distributes the message to all appropriate subscribers.

Key Features of Amazon SNS

Some of the key features of Amazon SNS are as follows:

  • Message Encryption: It offers Encrypted Topics to keep your messages safe from unauthorized and unknown access. By using Encryption Keys provided by AWS KMS, Server-Side Encryption protects the message contents stored in Amazon SNS Topics.
  • 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. 
  • 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.

What is Slack?

Slack Logo
Image Source

Slack is a multi-purpose communication and collaboration platform. It includes instant messaging, voice and video calls, as well as a suite of tools for groups to share information and collaborate. Slack offers applications for Windows, Mac, Android, Linux, and iOS, as well as a web browser. Slack messaging leverages Channels and Direct Messages to organize conversations and replace communications that would otherwise be spread across emails, text messages, or in-person meetings.

Public channels in Slack are accessible to all members of a workspace and can cover anything from various marketing and sales operations to random discussions and meme streams. Slack also allows you to send private messages to other team members, allowing you to have one-time communications or keep things organized between you and specific members of your team.

Key Features of Slack

Some of the key features of Slack include:

  • Third-Party Integrations: One of Slack’s most powerful features is integration with third-party services. These kinds of integrations allow you to use some of your favorite apps directly within Slack, eliminating the need to switch tabs, remember where that shared link went, or open another application just to double-check something.
  • Message Reminders: To avoid missing out on a task or something important that is within a message, Slack allows you to set a reminder right on that specific part of the message.
  • Advanced Search: Slack has a search bar that allows teams to easily find files. If you enter a search query that yields a large number of results, you can enclose it within quotes to reveal an exact match.

What is a Webhook?

Webhooks Logo
Image Source

A Webhook is a method of altering and modifying the behavior of web pages or web applications through the use of Custom Callbacks. It is essentially a user-defined HTTP Callback that is triggered by specific events. When the trigger event occurs on the source website, the Webhook Records it, Collects the Data, and Sends it in the form of an HTTP request to the specified URL. A trigger event can be a Blog Comment, a Sign-up, Form Submission, etc.

A Webhook delivers data to other applications as it happens, which means you get data immediately, unlike traditional APIs, which require you to Poll Data frequently in order to get it in real-time. Webhooks are now much more efficient for both providers and consumers. Webhooks are commonly used to connect two distinct applications. You can even leverage Webhooks to set up an event on one website to trigger an action on another. Later in this article, you will learn about how to set up SNS Slack Integration using webhooks.

Replicate Data in Minutes Using Hevo’s No-Code Data Pipeline

Hevo Data, a Fully-managed Data Pipeline platform, can help you automate, simplify & enrich your data replication process in a few clicks. With Hevo’s wide variety of connectors and blazing-fast Data Pipelines, you can extract & load data from 100+ Data Sources straight into your Data Warehouse or any Databases. To further streamline and prepare your data for analysis, you can process and enrich raw granular data using Hevo’s robust & built-in Transformation Layer without writing a single line of code!

GET STARTED WITH HEVO FOR FREE

Hevo is the fastest, easiest, and most reliable data replication platform that will save your engineering bandwidth and time multifold. Try our 14-day full access free trial today to experience an entirely automated hassle-free Data Replication!

How to Set up SNS Slack Integration?

Amazon SNS can be used to send notifications to HTTP(S) endpoints such as Webhook URLs. When confirming the HTTP(S) subscription, some webhooks expect JSON key-value pairs that Amazon SNS does not support. For example, Slack Webhooks anticipate a JSON request with a message string corresponding to a “text” key. For such cases, an AWS Lambda Function is used to transform the Amazon SNS message body for the webhook endpoint to process.

Follow the steps given below to set up SNS Slack Integration using webhooks:

SNS Slack Integration Step 1: Create an SNS Topic

The first step involved in setting up SNS Slack Integration requires you to create an SNS Topic. Follow the steps given below to do so:

  • Log in to Amazon SNS Console using the appropriate credentials.
  • Navigate to the sidebar menu and select the Topics option.
  • Click on the Create Topic button.
Creating an SNS Topic
Image Source
  • Now, give a unique name to your SNS topic and click on Create topic.

SNS Slack Integration Step 2: Create a Lambda Function

The second step involved in setting up SNS Slack Integration requires you to create a Lambda Function. Follow the below steps to do so:

  • Once you have successfully created your SNS topic, head over to the Lambda Console.
  • Navigate to the Functions tab and click on the Create Function button to create a new Lambda function.
Creating a new Lambda Function
Image Source
  • Now, give a unique name to your function and choose the language you want to write your function in.
Filling in the required parameters
Image Source
  • Once you are done filling in the required fields, click on Create Function.
  • Once the Lambda Function is successfully created, you need to add some custom code to send the message to the destination which is Slack in this case. The code given below can be used to send custom messages to a Slack channel:

Example Python Code for Slack

#!/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
    })

Note: Replace the URL with the Incoming Webhooks URL and the Channel name with the Destination Channel on Slack.

SNS Slack Integration Step 3: Configure a Test Event

Once you have added the custom code to your Lambda Function, it’s time to test the function using Lambda Console to set up SNS Slack Integration. Follow the steps given below to do so:

  • Save the Function code by clicking on the Save button, found at the top right corner.
  • Now click on the Test button located right next to the Save button.
Test Event
Image Source
  • In the Event Template field, select Amazon SNS Topic Notification and enter a unique name for the event.
  • Once you are done filling all the required fields, click on the Create button.
  • When the test event is completed, click on the Test button again and navigate to the Details section.
  • If the response code is 200, it means that the message was accepted by Webhook and delivered to the corresponding channel on Slack. This also marks the end of SNS Slack Integration.  

Once you follow all the above steps in the correct sequence, you will be able to set up SNS Slack Integration in a seamless manner!

What Makes Hevo’s Real-time Data Integration & Modeling Process Unique?

Transforming data can be a mammoth task without the right set of tools. Hevo’s automated platform empowers you with everything you need to have a smooth Data Collection, Processing, and Integration experience. Our platform has the following in store for you!

  • Auto Schema Mapping: Hevo takes away the tedious task of schema management & automatically detects the format of incoming data and replicates it to the destination schema.
  • Data Transformations: Best-in-class & Native Support for Complex Data Transformation at fingertips. Code & No-code Flexibility is designed for everyone.
  • Built to Scale: Exceptional Horizontal Scalability with Minimal Latency for Modern-data Needs.
  • Built-in Connectors: Support for 100+ Data Sources, including Databases, SaaS Platforms, Files & More. Native Webhooks & REST API Connector available for Custom Sources.
  • Blazing-fast Setup: Straightforward interface for new customers to work on, with minimal setup time.
  • Live Support: The Hevo team is available round the clock to extend exceptional support to its customers through chat, email, and support calls.
  • Exceptional Security: A Fault-tolerant Architecture that ensures Zero Data Loss.
Sign up here for a 14-Day Free Trial!

How to Add an SNS Topic Trigger to your Lambda function?

You can also subscribe your function to your SNS topic after sending an SNS message to Slack. To do so, add an SNS topic trigger to the Lambda console by following the steps given below:

  • Head over to the Functions page of the Lambda console and select your function.
  • Click on the Add Trigger option present under the Designer menu.
  • Under the Trigger Configuration, select a Trigger, and then choose SNS.
  • Select the SNS topic that you created previously.
  • Mark the Enable Trigger check box and then click on Add.

Once you have completed the above steps, messages published to the topic will be forwarded to the function, and then to your webhook. You can do this after setting up the SNS Slack Integration.

Conclusion

This blog introduced you to Amazon Simple Notification Service, Slack, and  Webhooks along with their key features. It further provided the steps that you can follow to set up SNS Slack Integration. If you want to integrate data from various data sources into your desired Database/destination for free and seamlessly visualize it in a BI tool of your choice, Hevo Data is the right choice for you! It will help simplify the ETL and management process of both the data sources and destinations.

Visit our Website to Explore Hevo

Hevo Data, a No-code Data Pipeline provides you with a consistent and reliable solution to manage data transfer between a variety of sources and a wide variety of Desired Destinations, with a few clicks. Hevo Data with its strong integration with 100+ sources (including 40+ free sources) allows you to not only export data from your desired data sources & load it to the destination of your choice, but also transform & enrich your data to make it analysis-ready so that you can focus on your key business needs and perform insightful analysis using BI tools.

Want to take Hevo for a spin?

Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand. You can also have a look at the unbeatable pricing that will help you choose the right plan for your business needs.

Share your experience of learning about SNS Slack Integration in the comments below!

No-code Data Pipeline For your Data Warehouse