Sns To Slack

  



AWS Chatbot works by redirecting customers’ SNS topic notifications to developers’ Slack channels or Chime chat rooms. Administrators can add the alerts to Slack from directly within the AWS. Sending notifications to Slack using the Chatbot Terraform module. To send notifications, for example, when an AWS CodePipeline project starts or finishes, we will create a SNS topic and configure Chatbot to map that SNS topic. Then, we create an awscodestarnotificationsnotificationrule that notifies the SNS topic when one of these events. A python library to send cloudwatch alarm notifications to Slack. Install the package. Pip install cloudwatchalarmtoslack It is expected this will be used as a part of a lambda. From cloudwatchalarmtoslack.entrypoint import CloudwatchAlarmNotifier def lambdahandler(event, context): CloudwatchAlarmNotifier.handleevent(event).

Latest version

Released:

A python library to send cloudwatch alarm events from sns to slack

Project description

Cloudwatch Alarm to Slack Notifier

A python library to send cloudwatch alarm notifications to Slack.

Usage

  • Install the package.
  • It is expected this will be used as a part of a lambda.
  • It is required the following environment variable be set:

    • SLACK_BOT_TOKEN: Bot token of the slack app which should have the chat:write permissions.
    • SLACK_CHANNEL: ID of the Slack channel to which notification should be sent to.

If there is another usecase, please open an issue and let me know :)

Release historyRelease notifications | RSS feed

Download files

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

Files for cloudwatch-alarm-to-slack, version 1.0.0
Filename, sizeFile typePython versionUpload dateHashes
Filename, size cloudwatch_alarm_to_slack-1.0.0-py3-none-any.whl (13.5 kB) File type Wheel Python version py3 Upload dateHashes
Filename, size cloudwatch_alarm_to_slack-1.0.0.tar.gz (7.8 kB) File type Source Python version None Upload dateHashes
Close

Hashes for cloudwatch_alarm_to_slack-1.0.0-py3-none-any.whl

Hashes for cloudwatch_alarm_to_slack-1.0.0-py3-none-any.whl
AlgorithmHash digest
SHA256d238aa72576700f938ecbf9f3f4e3c73d73083b3b77c6868bc2630c67d511d64
MD54347a3857838daf95c74b946ad6db061
BLAKE2-2569e1cbef806150ddee8bee22266f968d94cd8c14e9ac4cac076e7effaa8ec28f3
Close

Hashes for cloudwatch_alarm_to_slack-1.0.0.tar.gz

Hashes for cloudwatch_alarm_to_slack-1.0.0.tar.gz
AlgorithmHash digest
SHA256c84c6fd4029843474f6b405cd4b99da99f356e905cbd634b87a5afba50642654
MD5dfd4625a8720e69d04e3fc1a94a2d2a4
BLAKE2-256e0ee51471bdc0fc137e26c5213b77de96134824d25e919d516252679e9d4a5c6

I want to use webhooks to connect my AWS environment to my Amazon Chime chat room, or to my Slack or Microsoft Teams channel. How do I send notifications from Amazon Simple Notification Service (Amazon SNS) to a webhook?

Short description

Sns To Slack Terraform

You can use Amazon SNS to send notification messages to HTTP(S) endpoints, such as webhook URLs. However, some webhooks expect JSON key-value pairs that Amazon SNS doesn't support when confirming the HTTP(S) subscription.

For example, Amazon Chime webhooks expect a JSON request with a message string corresponding to a 'Content' key. Similarly, Slack and Microsoft Teams webhooks both expect a JSON request with a message string corresponding to a 'text' key.

To transform the Amazon SNS message body JSON document for the webhook endpoint to process, you use an AWS Lambda function.

Note: For a list of the key-value pairs in the Amazon SNS message body JSON document, see HTTP/HTTPS notification JSON format.

Resolution

Create an SNS topic

If you haven't done so already, create an SNS topic with a unique name.

Create a Lambda function

For instructions to create a Lambda function, see Getting Started with AWS Lambda. For more information, see Using AWS Lambda with Amazon SNS.

Your Lambda function code must include logic to transform your SNS topic's notification messages for the type of webhook endpoint that you're using. For examples, see the following Python code snippets for Amazon Chime, Slack, and Microsoft Teams webhooks. These code examples are provided as-is. They're compatible with the Python 3.6 runtime.

Example Python code snippet for Amazon Chime

Sns To Slack

Aws Lambda Webhook

Amazon Chime webhooks expect a JSON request with a message string corresponding to a 'Content' key. For more information, see Webhooks for Amazon Chime.

Note: In this example function code for Amazon Chime webhooks, replace https://hooks.chime.aws/incomingwebhooks/xxxxxxx with the webhook URL.

Example Python code snippet for Slack

Slack Incoming Webhooks expect a JSON request with a message string corresponding to a 'text' key. They also support message customization, such as adding a user name and icon, or overriding the webhook's default channel. For more information, see Sending messages using incoming webhooks on the Slack website.

Note: In this example function code for Slack Incoming Webhooks, replace https://hooks.slack.com/services/xxxxxxx with the Incoming Webhook URL. Also replace #CHANNEL_NAME with the destination channel's name.

Aws

Example Python code snippet for Microsoft Teams

Microsoft Teams incoming webhooks also expect a JSON request with a message string corresponding to a 'text' key. For more information, see Setting up a custom incoming webhook on the Microsoft Docs website.

Note: In this example function code for Microsoft Teams incoming webhooks, replace https://outlook.office.com/webhook/xxxxxxx with the webhook URL.

Test the Lambda function

  1. On the Functions page of the Lambda console, choose your function.
  2. At the top right, choose Select a test event. Then, choose Configure test events.
  3. In the Configure test event dialog box, choose Create new test event.
  4. For Event template, choose Amazon SNS Topic Notification.
  5. For Event name, enter a name for the test event.
  6. Choose Create.
  7. Choose Test.
  8. Review the Execution result.

If the test invocation succeeds with a 200 status code, then the Amazon SNS notification message is accepted by your webhook, which delivers it to the corresponding channel. If the invocation fails with a 4xx status code, then check the webhook URL and verify that the key-value pair is correct and accepted by your destination webhook.

For more information about testing functions in the Lambda console, see Invoke the Lambda function.

Aws Slack Group

Add an SNS topic trigger to your Lambda function

After sending an SNS message to your webhook as a test in the Lambda console, subscribe your function to your SNS topic. To configure this from the Lambda console, add an SNS topic trigger by doing the following:

  1. On the Functions page of the Lambda console, choose your function.
  2. Under Designer, choose Add trigger. For more information, see Use the designer.
  3. Under Trigger configuration, choose Select a trigger, and then choose SNS.
  4. For SNS topic, choose the SNS topic that you created earlier.
  5. Select the Enable trigger check box.
  6. Choose Add.

For more information, see Configuring functions in the AWS Lambda Console.

With your function subscribed to your SNS topic, messages published to the topic are forwarded to the function, and then to your webhook.

Note: For information on how to get Amazon SNS notifications through other AWS services, see Using AWS Chatbot with other AWS services.

Related information

Adding webhooks to chat rooms (Amazon Chime User Guide)

Sns

Raw message delivery (Amazon SNS FAQs)

Related videos

Close