How to Send AWS Notifications (AWS SNS) to Microsoft Teams
Published: 2021-10-23 11:21:34

---
source: https://ictpro.co.nz/how-to-send-aws-notifications-aws-sns-to-microsoft-teams/
author: Anuvindh
---





### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zpdxb0bgw9ppfdxtzq00.png)

Search and install  **Incoming Webhook** and click **configure.**
![Configure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/akk2u7nnseuo4441170o.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70dxmuadihy9kp9il58k.png)

**b) Let’s create a lambda function.** 

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

![CreateLambda](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inj1n42fwrp5eqmsq3ug.png)

Once you have created  lamda function 

**Copy this code** to lambda function or get it from the [**github**](https://github.com/anuvindhs/Amazon-SNS-to-Microsoft-Teams-Slack.git)  . **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
})
```
![codelambda](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1do0stv6uvyc8700qysx.png)

Now click Deploy.  you will be able to see ![Deploy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6gendpjbt03mr2vklkg1.png)

**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1owm5l1vqwxc9hkbuixx.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d8xwkxlp6wmkwwssya8i.png)
Now Check your Teams Channel , you will be able to see the SNS message.
![ALertTeams](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfv1xwzqy27x7iiavg94.png)
#### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iia6mdfl720qkg95sd9u.png)

**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/asp8j70n2vou4j57d1yt.png)
**Step Three**

Now Click and **confirm the subscription.**
![ConfirmSub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/spzlh26cqdlgjs4x4acg.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/03ag4fltts9xve1oh7lk.png)
tadaaaaaaaaa…………………..
![SNSonTeams1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e737iqfcsiohr5vih7d6.png)

![introimage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tpf2trjki62z5qmrgmwf.png)
---
### What will be your Choice , with Lambda or direct to teams ?
---


{% user anuvindhs %}