DEV Community

Cover image for How to Send AWS Notifications (AWS SNS) to Microsoft Teams
Anuvindh for AWS Community Builders

Posted on • Edited on

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

Introduction

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 for your servers. Monitoring is everything to keep you secure, from malicious activities that can be impacted your app.

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.Using lambda and webhook

2.Directly to Microsoft Teams

1.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.
Connectors

Search and install  Incoming Webhook and click configure.
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
webhook

b) Let’s create a lambda function.

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

CreateLambda

Once you have created  lamda function 

Copy this code to lambda function or get it from the 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
})
Enter fullscreen mode Exit fullscreen mode

codelambda

Now click Deploy. you will be able to see Deploy

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
Sub
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 
PubMSG
Now Check your Teams Channel , you will be able to see the SNS message.
ALertTeams

2. Send SNS Notifications without Lambda

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

a)Lets get a email of your channel

Consider this email as a notification end-point

GetEmailAddress

*b) Create Subscription & Confirm *

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

Now Click and confirm the subscription.
ConfirmSub
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

TestSNS
tadaaaaaaaaa…………………..
SNSonTeams1

introimage

What will be your Choice , with Lambda or direct to teams ?


Top comments (0)