Sns Slack



  1. Sns Slack Endpoint
  2. Aws Slack Channel
  3. Sns Slack
Latest version

Released:

AWS package which creates a Slack subscriber to a SNS Topic.

Want to make sure the team on Slack is always up to date with the messages you're sending through Amazon SNS? Set up this Amazon SNS-Slack integration and they will be, automatically receiving a message on Slack for every new Amazon SNS message, with a specific topic name, from then on. Using Lambda Function with Amazon SNS - Amazon SNS is a service used for push notification. In this chapter, we will explain working of AWS Lambda and Amazon SNS with the help of an example where will. We would like to show you a description here but the site won’t allow us.

Try Slack for free with your teammates. All it takes is an email address to get started. This browser is no longer supported. We know it's a hassle to switch browsers, but we want your experience of Slack to be fast, secure, and the best it can possibly be.

Project description

AWS SNS Slack Subscriber

A library that creates a slack subscriber to your aws sns topic.

Remarks

The project is written by Laimonas Sutkus and is owned byiDenfy. This is an open sourcelibrary intended to be used by anyone. iDenfy aimsto share its knowledge and educate market for better and more secure IT infrastructure.

Related technology

This project utilizes the following technology:

  • AWS (Amazon Web Services).
  • AWS CDK (Amazon Web Services Cloud Development Kit).
  • AWS Lambda.
  • AWS Sns.
  • Slack.

Install

The project is built and uploaded to PyPi. Install it by using pip.

Sns

Or directly install it through source.

Description

When you have SNS Topics, you may subscribe to them with various ways. For example,email subscription will send an email to a desired email address when a notificationis pushed to a SNS Topic. Most of the time email subscription is not ideal as it mayclutter your email box. Hence, there are other ways to subscribe to a SNS Topic. Wethink the most convenient way to subscribe to SNS Topic is a Lambda Function integrationwhich sends callbacks to your specified Slack channel. This library project is about that.It creates a 'Slack subscription' with a help of Lambda.

Examples

Create sns slack subscriber as any other lambda function:

2.2.0

Force update 1.60.0 and add upper bound of 2.0.0.

2.1.0

URL and AWS CDK updates.

1.1.1

Completely refactor functionality. Add an explicit pipeline handler.Rewrite everything on python.

Sns Slack Endpoint

1.1.1

Add js file to manifest.

1.1.0

Aws Slack Channel

Add ability to specify slack channel.

1.0.0

Initial commit.

Release historyRelease notifications | RSS feed

2.2.0

Sns Slack

2.1.0

2.0.0

1.1.1

1.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aws-sns-slack-subscriber, version 2.2.0
Filename, sizeFile typePython versionUpload dateHashes
Filename, size aws_sns_slack_subscriber-2.2.0-py3-none-any.whl (21.3 kB) File type Wheel Python version py3 Upload dateHashes
Filename, size aws_sns_slack_subscriber-2.2.0.tar.gz (5.1 kB) File type Source Python version None Upload dateHashes
Close

Hashes for aws_sns_slack_subscriber-2.2.0-py3-none-any.whl

Hashes for aws_sns_slack_subscriber-2.2.0-py3-none-any.whl
AlgorithmHash digest
SHA256bfbd3f114f35fd02ee91dd0f86523a42904405642f2932d38559ac6d188c96d3
MD56a1693dbf8e715ef63da562eb5fe8297
BLAKE2-2563d62a0c990e087d34df882c18ed70ef28e07e3f5402d10a6597a562db49490e8
Close

Hashes for aws_sns_slack_subscriber-2.2.0.tar.gz

Hashes for aws_sns_slack_subscriber-2.2.0.tar.gz
AlgorithmHash digest
SHA256d4a06269d5fb00f49da9c92db882529ecce47caa765257070bb07a425077d011
MD558e65305a7acb90707ac20f3774b13c8
BLAKE2-25677a48195da732880ac6f45e4665e7eef861868d78b7b3cc1739fe0530a0d808e
sns-to-slack.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
''
Follow these steps to configure the webhook in Slack:
1. Navigate to https://<your-team-domain>.slack.com/services/new
2. Search for and select 'Incoming WebHooks'.
3. Choose the default channel where messages will be sent and click 'Add Incoming WebHooks Integration'.
4. Copy the webhook URL from the setup instructions and use it in the next section.
Follow these steps to encrypt your Slack hook URL for use in this function:
1. Create a KMS key - http://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html.
@hayd note: It seems to be important that the key, role and lambda are all in the same region...
2. Encrypt the event collector token using the AWS CLI.
$ aws kms encrypt --key-id alias/<KMS key name> --plaintext '<SLACK_HOOK_URL>'
Note: You must exclude the protocol from the URL (e.g. 'hooks.slack.com/services/abc123').
3. Copy the base-64 encoded, encrypted key (CiphertextBlob) to the ENCRYPTED_HOOK_URL variable.
@hayd note: This is the output of the above `aws kms encrypt` command verbatim.
4. Give your function's role permission for the kms:Decrypt action.
Example:
{
'Version': '2012-10-17',
'Statement': [
{
'Effect': 'Allow',
'Action': [
'kms:Decrypt'
],
'Resource': [
'<your KMS key ARN>'
]
}
]
}
''
from __future__ importprint_function
importboto3
importjson
importlogging
importre
frombase64importb64decode
fromurllib2importRequest, urlopen, URLError, HTTPError
# value of the CiphertextBlob key in output of $ aws kms encrypt --key-id alias/<KMS key name> --plaintext '<SLACK_HOOK_URL>'
ENCRYPTED_HOOK_URL='CiC9...'
HOOK_URL='https://'+boto3.client('kms').decrypt(CiphertextBlob=b64decode(ENCRYPTED_HOOK_URL))['Plaintext']
logger=logging.getLogger()
logger.setLevel(logging.INFO)
deflambda_handler(event, context):
logger.info('Event: '+str(event))
state_dict= {'Ok': ':thumbsup:', 'Info': ':information_source:', 'Severe': ':exclamation:'}
d=dict(line.split(': ') forlineinevent['Records'][0]['Sns']['Message'].splitlines() if': 'inline)
transition=re.match('Environment health has transitioned from (.*) to (.*?).', d['Message'])
iftransition:
original, became=map(lambdax: state_dict.get(x, x), transition.groups())
d['Message'] ='*Health*: '+original+u' ⟶ '+became+'n_'+d['Message'].split('. ', 1)[1] +'_'
slack_message= {
'channel': 'build'if'New application version was deployed'ind['Message'] else'beanstalk',
'text': d['Message'],
'username': d['Environment'],
'icon_emoji': ':tophat:'
}
req=Request(HOOK_URL, json.dumps(slack_message))
try:
response=urlopen(req)
response.read()
logger.info('Message posted to %s', slack_message['channel'])
exceptHTTPErrorase:
logger.error('Request failed: %d %s', e.code, e.reason)
exceptURLErrorase:
logger.error('Server connection failed: %s', e.reason)

commented May 17, 2020

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment