Push Notifications From Amazon SNS to MS Team as a Webhook

Push Notification from Amazon SNS to MS Team via Lambda Function in NodeJS and Python

Parth Trambadiya
Enlear Academy

--

We all know about Amazon SNS, Amazon Simple Notification Service (Amazon SNS) is a managed service that provides message delivery from publishers to subscribers (also known as producers and consumers).

Due to the COVID-19 pandemic, Microsoft Teams has become a video conference application for students and organizations. Moreover, in Microsoft Teams, we can integrate many other applications, such as Forms, PowerBI, Adobe Sign, etc., which means almost everything.

Let’s assume you are running applications related to student attendance, student submission, or any other type of applications, and for notification service, you are using Amazon SNS. You wanted to get all notifications from SNS to MS Team. This sounds good, but there is no direct integration option in Amazon SNS for MS Team. Therefore, we can not create MS Team as a subscriber of Amazon SNS.

To do this, we need to use webhook in MS Team, and almost all webhooks are expecting JSON data as a response, so we need to use lambda function, and lambda can be integrated as a subscriber in Amazon SNS.

Simple Architecture

Let’s implement this.

Step — 1

Go to Microsoft Teams create a new Team with your requirements. If you have already created a Team in MS Teams, then you may skip this step.

Step — 2

Inside that newly created Team, go to the Manage Team. In the managing team, move to the Apps tab and click on More Apps. On the Apps window, search for Incoming Webhook and add that App to Team.

Select channel according to your project. I am selecting the General channel.

Once you click on Set up a Connector, it will prompt one window on that window to fill up all details and click on Create. And copy the webhook URL from that window.

If it successfully configures, then you will get this kind of message in your channel.

Step — 3

Now, go to the AWS Management Console, go to AWS Lambda Console, create a new Lambda function with the latest version of Python, and leave other settings default.

If you are working on NodeJS then clone the given repository, install the required dependencies, zip it and create lambda function with node.js runtime and upload it to the Lambda function.

Git Repository: https://github.com/ParthTrambadiya/ms-team-webhook-nodejs.git

Change your lambda code with the above code and enter your MS Teams webhook URL in url a variable. Don’t forget to deploy your code.

If you want to test your Lambda function from the Lambda console, you can create an SNS Topic Notification test event from the Test tab and fire test. If you will able to get messages in MS Team, then your lambda function works perfectly.

Step — 4

Now let’s create the SNS Topic, so go to the SNS Console. And create a new topic. Topic type should be Standard, enter a topic name, and leave other settings default if you do not have specific requirements.

Now let’s create subscribers on that topic, so click on the Create Subscription button. In subscription, Protocol should be AWS Lambda, and in Endpoint search your lambda function name, which we have created in the previous step.

Leave other settings default if you are not having specific requirements and create a subscription.

Till now, we have done with the configuration, so let’s test this.

Testing

Go to that topic, which we have created previously, and click on Publish Message button to publish the message.

Write a Message subject if you want in Message Details.

In Message Body, select Identical payload for all delivery protocols, and write a message in the given textbox below and publish the message.

Go to your MS Teams, go inside the channel we selected above, and check for messages. For example, in MS Team, you can see a message sent by SNS.

For any query, contact me on LinkedIn or My Portfolio, and do not forget to follow me on LinkedIn and medium.

LinkedIn: https://www.linkedin.com/in/parth-trambadiya/
Medium: trambadiyaparth.medium.com
Portfolio: https://parthtrambadiya.me

--

--

3X AWS | 1X Azure | 1X OCI Certified Cloud Enthusiast | DevOps | Solution Architect | Writer @ Enlear Academy | Writer @ AWS in Plain English