How to Send AWS Notifications (AWS SNS) to Microsoft Teams

If you are a Cloud Administrator, System Engineer, Security Administrations, Governance Team, or IT Manager then this is a post for you.

As a leading Cloud provider, AWS can be scaled to millions of requests to your servers. Monitoring is everything to keep you secure, from malicious activities that can be impacted to your Comapny.

Your company might use MS teams as your first point for notification APP or a team channel. In such situations, you need to send notifications to the team’s channel. 

Consider Sernarios like :- 

  • Alerts from your CloudWatch dashboard 
  • Security hub Alerts 
  • Cloud trail events 
  • Custom reports to your governance team or Senior Management 
  • Your app wants to send notifications to  MS teams 

Today you will be learning two ways to implement a solution for such scenarios.

1.Directly to Microsoft Teams
2.Using lambda and webhook

Let's get started

1. Send SNS Notifications without Lambda

Setup and forget, An out-of-the-box idea came into my mind.

Step One 

Get email of your channel

Consider this email as a notification end-point


Step two

Now copy that email & go to SNS and subscribe to that email, and confirm the subscription from your Chat room.

Step Three

Now Click and confirm the subscription.

Congratulations you have successfully configured, Now let’s test it. Go to your Topic and Click Publish message . Now give a subject name and a message and click Publish Message 

tadaaaaaaaaa…………………..

2.Using Lambda and Webhook​

AWS Services Used

  • Lambda
  • SNS

a) Let’s get the Webhook from Microsoft Teams. 

Goto your channel , click on to three dots and click connectors.


Search and install  Incoming Webhook and click configure.


Now you can Name your Webhook and upload a logo if necessary and Click create.

A webhook URL will be prompted, make a note of it

 

b) Let’s create a lambda function. 

 Name your Lambda Function and select latest python version and click Create Function

Once you have created  lamda function 

Copy this code to lambda function or get it from the github GitHub Logos and Usage · GitHub . Replace the default url with your webhook url. Also Make a note of Lambda function ARN

#!/usr/bin/python3.8
import urllib3
import json
http = urllib3.PoolManager()
def lambda_handler(event, context):
url = “your webhook url”
msg = {
“text”: event[‘Records’][0][‘Sns’][‘Message’]
}
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
})

 

Now click Deploy.  you will be able to see 

C) Now let’s configure SNS

Goto your SNS tops and click to Create Subscription

Select your Protocol as Lambda and Paste ARN of your Lambda and Now Click Create subscription

Congratulations you have successfully configured, Now let’s test it. Go to your Topic and Click Publish message . Now give a subject name and a message and click Publish Message 

Now Check your Teams Channel , you will be able to see the SNS message.

Congratulations. 

Subscribe Now

Share on

Share on facebook
Share on twitter
Share on linkedin
Share on google
Share on whatsapp
Share on email