Skip to content

This AWS CDK Construct is designed to post messages sent from an SNS topic to a Slack Webhook via a Lambda function.

License

Notifications You must be signed in to change notification settings

gammarers/aws-sns-slack-message-lambda-subscription

Repository files navigation

AWS SNS Slack Message Lambda Subscription

GitHub npm (scoped) PyPI Nuget GitHub Workflow Status (branch) GitHub release (latest SemVer)

This AWS CDK Construct is designed to post messages sent from an SNS topic to a Slack Webhook via a Lambda function. The Lambda function accepts JSON text as a message, formats it for Slack, and sends it to the Slack Webhook API.

Incoming Sample Message

Installation

TypeScript

install by npm

npm install @gammarers/aws-sns-slack-message-lambda-subscription

install by yarn

yarn add @gammarers/aws-sns-slack-message-lambda-subscription

Python

pip install gammarers.aws-sns-slack-message-lambda-subscription

C# / .NET

dotnet add package Gammarers.CDK.AWS.SNSSlackMessageLambdaSubscription

Example

Please save it in AWS Secrets Manager in the following format.

get your slack webhook url parts

https://hooks.slack.com/services/<workspace>/<channel>/<whebook>
SecretKey SecretValue
Workspace <workspace>
Channel <channel>
Webhook <whebook>

Code

import { SNSSlackMessageLambdaSubscription } from '@gammarer/aws-sns-slack-message-lambda-subscription';

declare const topic: sns.Topic;

new SNSSlackMessageLambdaSubscription(stack, 'SNSSlackMessageLambdaSubscription', {
  topic,
  slackWebhookSecretName: 'slak-webhook', // alredy saved slack webhook info.
});
{
    "text": ":mega: *TEST*",
    "attachments": [{
        "color": "#2eb886",
        "title": "CodePipeline pipeline execution *SUCCEED*",
        "title_link": "https://github.com/yicr",
        "fields": [
            {
                "title": "Pipeline",
                "value": "pipeline-name"
            }
        ]
    }]
}

License

This project is licensed under the Apache-2.0 License.

About

This AWS CDK Construct is designed to post messages sent from an SNS topic to a Slack Webhook via a Lambda function.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published