Publish a message received from SNS to Slack.
This service requires an SNS topic for it to subscribe to. It will receive SNS messages formatted for the chat.postMessage Slack API for publishing to Slack.
Example service:
This service requires the creation of a Slack App in your organization. It will use the credentials and permissions of that app in order to post messages.
click the link below to sign into the desired Slack workspace.
Click the link below and on that page click the "Create New App" button.
Give the app a name and select the workspace.
OAuth Tokens & Redirect URLs
Click "OAuth & Permissions" in the left side bar. On that page under the OAuth Tokens & Redirect URLs section obtain an OAuth Access Token. You will need that to deploy this service.
Under the Scopes section add the following:
- channels:read
- chat:write:bot
Once you've saved settings, your Slack bot is configured.
- Event Type: AWS SNS
- SNS Message: Message should be a JSON formatted string that conforms to the chat.postMessage Slack API method. See also slack-message-schema.json in this repository to understand more about the message shape.
You will need the following in order to deploy and use this service.
- A Slack App API key
- A Slack channel
- The CloudFormation export value of the SNS topic ARN this should subscribe to.
In addition, this service can optionally publish responses from the Slack API to an SNS topic so the responses may be processed. You may toggle this attribute of the stack as well.
This application is intended to be deployed using AWS Serverless Application Repository. However, Serverless Framework is also supported.
When deploying via Serverless Application Repository or CloudFormation, you will be presented with the following parameters to configure.
- SlackApiToken (Required): API token to use when publishing to slack.
- SlackDefaultChannel: Channel messages should be published to.
- SnsPublishResponse: Name of the CloudFormation export to find the event source SNS topic to subscribe
- SnsPublisherTopicExport (Required): Whether to publish Slack API responses to an SNS topic.
AWS Serverless Application Repository: aws-sns-to-slack-publisher
To configure the deployment of this service, the following environment variables may be set when running sls deploy
.
- SLACK_API_TOKEN (Required): API token to use when publishing to slack.
- SLACK_DEFAULT_CHANNEL: Channel messages should be published to.
- SNS_PUBLISHER_TOPIC_EXPORT (Required): Name of the CloudFormation export to find the event source SNS topic to subscribe to.
- SNS_PUBLISH_RESPONSE (Values: 'true'|'false'): Whether to publish Slack API responses to an SNS topic.
$ npm install -g serverless
$ npm install
$ SLACK_API_TOKEN=|TOKEN| SNS_PUBLISHER_TOPIC_EXPORT=|CFN_EXPORT| serverless deploy -v
These values may be used by other services in your AWS infrastructure.
- ${AWS::StackName}-SlackResponseSnsTopicArn: Topic to which Slack publishing responses are sent.