Skip to content

Send AWS Notifications (AWS SNS) to Microsoft Teams , Slack or other chat rooms

Notifications You must be signed in to change notification settings

anuvindhs/Amazon-SNS-to-Microsoft-Teams-Slack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 

Repository files navigation

Amazon-SNS-to-Microsoft-Teams-Slack

For tutorial Please visit

Read On Dev.to ,
Read on iCTPro.co.nz


introimage

Code snippet for Microsoft Teams

#!/usr/bin/python3.6
import urllib3 
import json
http = urllib3.PoolManager() 
def lambda_handler(event, context): 
    url = "https://outlook.office.com/webhook/xxxxxxx"    
    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
    })
    

Code snippet 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": "#YOUR_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
    })

About

Send AWS Notifications (AWS SNS) to Microsoft Teams , Slack or other chat rooms

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published