-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
229 lines (220 loc) · 6.03 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
service: SlackingBot
frameworkVersion: ">=1.26.0 <2.0.0"
plugins:
- serverless-python-requirements
custom:
#credentialsProfile: oph-opintopolku-session-dev
pythonRequirements:
dockerizePip: false
region: eu-west-1
domainName: slackingbot.goforecrew.com
stage: dev
environmentName: dev
channel: channel-${self:custom.environmentName}
#topics: "${self:custom.channel},flowdock-notifications"
channels: "flowdock-notifications"
channelListParameter: channelList
messageTable: messages-${self:custom.environmentName}
authorizationTableName: slackingbot-authorization-${self:custom.environmentName}
provider:
name: aws
region: ${self:custom.region}
#profile: ${self:custom.credentialsProfile}
tracing: true
runtime: python3.6
stage: ${self:custom.stage}
endpointType: REGIONAL
apiKeys:
- ${self:custom.stage}-apikey
usagePlan:
quota:
limit: 5000
offset: 2
period: MONTH
throttle:
burstLimit: 200
rateLimit: 100
stackTags:
STACK: "${self:service}"
REGION: "${self:custom.region}"
#usagePlan:
# quota:
# limit: 5000
# offset: 2
# period: MONTH
# throttle:
# burstLimit: 200
# rateLimit: 100
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:BatchWriteItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:Scan
- dynamodb:GetItem
Resource:
- "arn:aws:dynamodb:${self:custom.region}:*:table/${self:custom.messageTable}"
- "arn:aws:dynamodb:${self:custom.region}:*:table/${self:custom.authorizationTableName}"
- Effect: Allow
Action:
- SNS:Publish
Resource: "*"
- Effect: Allow
Action:
- xray:PutTelemetryRecords
- xray:PutTraceSegments
Resource: "*"
- Effect: Allow
Action:
- ssm:GetParameter
- ssm:GetParameters
- ssm:*
Resource:
- 'Fn::Join':
- ':'
-
- 'arn:aws:ssm'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'parameter/maintenance'
- 'Fn::Join':
- ':'
-
- 'arn:aws:ssm'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'parameter/channelList'
- 'Fn::Join':
- ':'
-
- 'arn:aws:ssm'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'parameter/BOT_TOKEN'
- 'Fn::Join':
- ':'
-
- 'arn:aws:ssm'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'parameter/SLACK_URL'
- 'Fn::Join':
- ':'
-
- 'arn:aws:ssm'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'parameter/VERIFICATION_TOKEN'
environment:
CHANNEL_NAME: ${self:custom.channel}
CHANNEL_LIST_PARAMETER: ${self:custom.channelListParameter}
ALARM_TABLE: ${self:custom.messageTable}
AUTHORIZATION_TABLE: ${self:custom.authorizationTableName}
REGION: ${self:custom.region}
functions:
GetSentMessages:
handler: api.get_historical_messages
memorySize: 2048
events:
- http:
path: messages
method: get
cors: true
authorizer:
name: AuthorizerFunc
resultTtlInSeconds: 10
identitySource: method.request.header.Authorization
identityValidationExpression: Bearer .*
type: token
SendMessage:
handler: api.send_slack_message
memorySize: 2048
events:
- http:
path: messages
method: post
cors: true
authorizer:
name: AuthorizerFunc
resultTtlInSeconds: 10
identitySource: method.request.header.Authorization
identityValidationExpression: Bearer .*
type: token
SlackEvent:
handler: api.slack_event_handler
memorySize: 2048
events:
- http:
path: events
method: post
cors: true
# authorizer:
# name: AuthorizerFunc
# resultTtlInSeconds: 10
# identitySource: method.request.header.Authorization
# identityValidationExpression: Bearer .*
# type: token
AuthorizerFunc:
handler: authorizer.handler
memorySize: 3008
# you can add CloudFormation resource templates here
#resources:
# Resources:
# NewResource:
# Type: AWS::S3::Bucket
# Properties:
# BucketName: my-new-bucket
# Outputs:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"
resources:
Description: "Serverless stack for SlackingBot"
Resources:
messageChannel:
Type: AWS::SNS::Topic
Properties:
DisplayName: ${self:custom.channel}
TopicName: ${self:custom.channel}
MessagesTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.messageTable}
AttributeDefinitions:
- AttributeName: id
AttributeType: N
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
AuthorizationsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.authorizationTableName}
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ControlParameter:
Type: AWS::SSM::Parameter
Properties:
Name: maintenance
Type: String
Value: "false"
Description: "SSM Parameter controlling messaging publishing."
MessageChannels:
Type: AWS::SSM::Parameter
Properties:
Name: ${self:custom.channelListParameter}
Type: StringList
Value: ${self:custom.channels}
Description: "SSM Parameter for channel list"