Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
129 lines (102 sloc) 3.31 KB
# <DESCRIBE SERVICE>
service: aws-sns-to-slack-publisher
plugins:
- serverless-python-requirements
- serverless-iam-roles-per-function
- serverless-sam
custom:
stage: "${opt:stage, env:SLS_STAGE, 'dev'}"
profile: "${opt:aws-profile, env:AWS_PROFILE, env:AWS_DEFAULT_PROFILE, 'default'}"
log_level: "${env:LOG_LEVEL, 'INFO'}"
slack_api_token: "${env:SLACK_API_TOKEN, 'INSERT_TOKEN'}"
# NOTE: passing in a default channel name with the leading '#' triggers an
# issue with SLS variable interpolation
slack_default_channel: "${env:SLACK_DEFAULT_CHANNEL, 'notifications'}"
# If you don't need the SNS response published, then don't publish it.
sns_publish_response: "${env:SNS_PUBLISH_RESPONSE, 'false'}"
# Name of export to find SNS topic ARN to subscribe to.
sns_publisher_topic_export: "${env:SNS_PUBLISHER_TOPIC_EXPORT, ''}"
pythonRequirements:
dockerizePip: false
provider:
name: aws
profile: ${self:custom.profile}
stage: ${self:custom.stage}
runtime: python3.6
environment:
LOG_LEVEL: ${self:custom.log_level}
stackTags:
x-service: aws-sns-to-slack-publisher
x-stack: ${self:service}-${self:provider.stage}
functions:
SlackPublish:
handler: handlers/aws_sns_to_slack_publisher.handler
description: "Publish message from SNS to Slack"
memorySize: 128
timeout: 60
iamRoleStatements:
- Effect: "Allow"
Action: "SNS:Publish"
Resource:
Ref: SlackResponseSnsTopic
environment:
SLACK_API_TOKEN:
Ref: SlackApiToken
SLACK_DEFAULT_CHANNEL:
Ref: SlackDefaultChannel
SNS_PUBLISH_RESPONSE:
Ref: SnsPublishResponse
RESPONSE_SNS_TOPIC_ARN:
Ref: SlackResponseSnsTopic
resources:
Parameters:
SlackApiToken:
Type: String
Description: "Slack API token"
Default: "${self:custom.slack_api_token}"
SlackDefaultChannel:
Type: String
Description: "Slack channel to publish to."
Default: "${self:custom.slack_default_channel}"
SnsPublishResponse:
Type: String
Description: "Whether or not to publish function response to Sns"
Default: "${self:custom.sns_publish_response}"
AllowedValues:
- true
- false
SnsPublisherTopicExport:
Type: String
Description: "Name of the CloudFormation export wit the Sns topic ARN to subscribe to"
Default: "${self:custom.sns_publisher_topic_export}"
Resources:
EventPublishSnsSubscription:
Type: "AWS::SNS::Subscription"
Properties:
TopicArn:
Fn::ImportValue:
Ref: SnsPublisherTopicExport
Protocol: lambda
Endpoint:
Fn::GetAtt:
- SlackPublishLambdaFunction
- Arn
S3BillingItemWriterLambdaPermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: "lambda:InvokeFunction"
FunctionName:
Ref: SlackPublishLambdaFunction
Principal: 'sns.amazonaws.com'
SourceArn:
Fn::ImportValue:
Ref: SnsPublisherTopicExport
SlackResponseSnsTopic:
Type: "AWS::SNS::Topic"
Outputs:
SlackResponseSnsTopicArn:
Description: "AWS SNS Topic ARN"
Value:
Ref: SlackResponseSnsTopic
Export:
Name: "${self:service}-${self:provider.stage}-SlackResponseSnsTopicArn"
You can’t perform that action at this time.