Setting up AWS SNS Webhooks Integration Simplified: 3 Easy Steps

Last Modified: December 29th, 2022

AWS SNS Webhooks Integration

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 directly integrating with third-party applications, instead, it requires Webhooks to deliver SNS messages to third-party applications. Hence, an AWS SNS Webhooks Integration makes absolute sense.

Upon a complete walkthrough of this article, you will gain a decent understanding of Amazon SNS and Webhooks. This article will also provide you with a step-by-step guide to set up AWS SNS Webhooks Integration from scratch. Read along to learn more about AWS SNS Webhooks Integration!

Table of Contents

Prerequisites

  • An active AWS account.

Introduction to 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 certain 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.

Introduction to Webhooks

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 Amazon SNS Webhooks Integration.

Simplify Webhooks ETL & Analysis using Hevo’s No-code Data Pipeline

Hevo Data, a No-code Data Pipeline helps to load data from any data source such as Databases, SaaS applications, Cloud Storage, SDKs, and Streaming Services and simplifies the ETL process. It supports 100+ data sources (including 40+ free sources such as Webhooks) and is a 3-step process by just selecting the data source, providing valid credentials, and choosing the destination. In addition to the 100+ data sources, Hevo also allows integrating data from non-native sources using Hevo’s in-built Webhooks Connector. Hevo loads the data onto the desired Data Warehouse, enriches the data, and transforms it into an analysis-ready form without writing a single line of code.

Its completely Automated Pipeline offers data to be delivered in real-time without any loss from source to destination. Its fault-tolerant and scalable architecture ensures that the data is handled in a secure, consistent manner with zero data loss and supports different forms of data. The solutions provided are consistent and work with different Business Intelligence (BI) tools as well.

Get Started with Hevo for free

Check out why Hevo is the Best:

  • Secure: Hevo has a fault-tolerant architecture that ensures that the data is handled in a secure, consistent manner with zero data loss.
  • Schema Management: Hevo takes away the tedious task of schema management & automatically detects the schema of incoming data and maps it to the destination schema.
  • Connectors: Hevo supports 100+ data sources and integrations to SaaS platforms such as files, databases, analytics, and BI tools. It supports various destinations including Google BigQuery, Amazon Redshift, Snowflake, and Firebolt Data Warehouses; Amazon S3 Data Lakes; and MySQL, MongoDB, TokuDB, DynamoDB, PostgreSQL databases to name a few.  
  • Minimal Learning: Hevo, with its simple and interactive UI, is extremely simple for new customers to work on and perform operations.
  • Hevo Is Built To Scale: As the number of sources and the volume of your data grows, Hevo scales horizontally, handling millions of records per minute with very little latency.
  • Incremental Data Load: Hevo allows the transfer of data that has been modified in real-time. This ensures efficient utilization of bandwidth on both ends.
  • Live Support: The Hevo team is available round the clock to extend exceptional support to its customers through chat, email, and support calls.
  • Live Monitoring: Hevo allows you to monitor the data flow and check where your data is at a particular point in time.
Sign up here for a 14-day Free Trial!

Steps to Set up AWS SNS Webhooks Integration

Amazon SNS can be used to send notifications to HTTP(S) Endpoints such as Webhook URLs. However, when confirming the HTTP(S) subscription, some Webhooks expect JSON Key-Value pairs that Amazon SNS does not support.

Amazon Chime Webhooks, for example, anticipate a JSON request with a message string corresponding to a “Content” key. Similarly, the Webhooks for Slack and Microsoft Teams both expect a JSON request with a message string corresponding to a “Text” key. To overcome this barrier you can leverage an AWS Lambda Function to transform the Amazon SNS message body JSON document for the Webhook endpoint to process. The AWS SNS Webhooks Integration is a three-step process. Follow the steps given below to set up AWS SNS Webhooks Integration using Lambda Function:

Step 1: Create an SNS Topic

The first step involved in setting up SNS Webhooks 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 a new SNS Topic
Image Source
  • Now, give a unique name to your SNS topic and click on Create topic.

Step 2: Create a Lambda Function

The second step involved in building SNS Webhooks 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 Required Fields
Image Source
  • Once you are done filling the required field, 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. The code given below can be used to send custom messages to a Slack channel. In a similar way, you can also publish messages to Microsoft Teams, Amazon Chime, and other applications.

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.

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 Webhooks 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 the Webhook and delivered to the corresponding channel.
Code Response for SNS Webhook Integration
Image Source

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

Conclusion

This blog introduced you to Amazon Simple Notification Service and Webhooks along with their key features. It further provided the steps that you can follow to set up your AWS SNS Webhooks Integration seamlessly. 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 provides its users with a simpler platform for integrating data from 100+ data sources for Analysis. In addition to the 100+ data sources, Hevo also allows integrating data from non-native sources using Hevo’s in-built Webhooks Connector. It is a No-code Data Pipeline that can help you combine data from multiple sources. You can use it to transfer data from multiple data sources into your Data Warehouse, Database, or a destination of your choice. It also provides you with a consistent and reliable solution to manage data in real-time, ensuring that you always have Analysis-ready data in your desired destination.

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 our unbeatable pricing that will help you choose the right plan for your business needs!

Share your experience of learning about AWS SNS Webhooks Integration! Let us know in the comments section below!

mm
Former Research Analyst, Hevo Data

Rakesh is a Cloud Engineer with a passion for data, software architecture, and writing technical content. He has experience writing articles on various topics related to data integration and infrastructure.

No-code Data Pipeline for Webhooks