-
Notifications
You must be signed in to change notification settings - Fork 18
/
serverless.yml
128 lines (102 loc) · 3.31 KB
/
serverless.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# <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"