-
Notifications
You must be signed in to change notification settings - Fork 2
/
serverless.yaml
322 lines (305 loc) · 9.78 KB
/
serverless.yaml
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
service: agent-environment
provider:
name: aws
region: ${env:region, 'ap-southeast-2'}
runtime: nodejs12.x
endpointType: REGIONAL
stage: ${env:stage, 'dev'}
logRetentionInDays: 14
apiGateway:
shouldStartNameWithService: true
package:
individually: true
functions:
capturedata:
handler: lambda/CaptureData.handler
name: '${self:provider.stage}-${self:service}-capturedata'
description: 'Captures agent data and stores it in DynamoDB'
role: !GetAtt LambdaRole.Arn
events:
- http:
path: agentenvironment/data
method: post
cors: true
package:
exclude:
- '**'
include:
- 'lambda/CaptureData.js'
- 'node_modules/**'
memorySize: 128
timeout: 29
environment:
REGION: '${self:provider.region}'
STAGE: '${self:provider.stage}'
API_KEY: '${env:apiKey}'
ORIGIN: '${env:origin}'
AGENT_DATA_TABLE: !Ref AgentDataTable
verifylogin:
handler: lambda/VerifyLogin.handler
name: '${self:provider.stage}-${self:service}-verifylogin'
description: 'Verifies a login'
role: !GetAtt LambdaRole.Arn
package:
exclude:
- '**'
include:
- 'lambda/VerifyLogin.js'
- 'node_modules/**'
memorySize: 128
timeout: 29
environment:
REGION: '${self:provider.region}'
STAGE: '${self:provider.stage}'
API_KEY: '${env:apiKey}'
ORIGIN: '${env:origin}'
UPLOAD_BUCKET: !Ref S3BucketSite
UPLOAD_KEY: 'test_files/uploaded.test'
events:
- http:
path: agentenvironment/login
method: get
cors: true
processstream:
handler: lambda/ProcessStream.handler
name: '${self:provider.stage}-${self:service}-processstream'
description: 'Processes sream data from DynamoDB'
role: !GetAtt LambdaRole.Arn
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt: [AgentDataTable, StreamArn]
package:
exclude:
- '**'
include:
- 'lambda/ProcessStream.js'
- 'node_modules/**'
memorySize: 128
timeout: 60
environment:
REGION: '${self:provider.region}'
STAGE: '${self:provider.stage}'
AGENT_DATA_TABLE: !Ref AgentDataTable
S3_BUCKET: !Ref S3BucketData
S3_PREFIX: '${env:s3Prefix}'
resources:
Description: 'Amazon Connect Agent Environment'
Resources:
LambdaRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: '${self:provider.stage}-${self:service}-${self:provider.region}-role'
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Principal:
Service:
- 'lambda.amazonaws.com'
Action:
- 'sts:AssumeRole'
ManagedPolicyArns:
- !Ref LambdaPolicy
LambdaPolicy:
Type: 'AWS::IAM::ManagedPolicy'
Properties:
ManagedPolicyName: '${self:provider.stage}-${self:service}-${self:provider.region}-policy'
Description: 'Managed policy for Lambda execution'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:PutObject
Resource:
- 'arn:aws:s3:::${self:provider.stage}-${self:service}-data-${self:provider.region}-${env:accountNumber}'
- 'arn:aws:s3:::${self:provider.stage}-${self:service}-data-${self:provider.region}-${env:accountNumber}/*'
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:Query
- dynamodb:GetItem
- dynamodb:DeleteItem
- dynamodb:Scan
- dynamodb:UpdateItem
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
- dynamodb:ListShards
Resource:
- 'arn:aws:dynamodb:${self:provider.region}:${env:accountNumber}:table/${self:provider.stage}-agent-environment-data'
- 'arn:aws:dynamodb:${self:provider.region}:${env:accountNumber}:table/${self:provider.stage}-agent-environment-data/*'
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- 'arn:aws:logs:${self:provider.region}:${env:accountNumber}:log-group:/aws/lambda/*:*:*'
DynamoKMSKey:
Type: AWS::KMS::Key
Properties:
Description: !Sub 'Encrypts DynamoDB table data'
KeyPolicy:
Version: '2012-10-17'
Id: 'dynamo-${self:provider.stage}-${self:service}-key'
Statement:
-
Sid: 'Allow root administration of the key'
Effect: 'Allow'
Principal:
AWS: 'arn:aws:iam::${env:accountNumber}:root'
Action:
- 'kms:*'
Resource: '*'
-
Sid: 'Allow root use of the key'
Effect: 'Allow'
Principal:
AWS: 'arn:aws:iam::${env:accountNumber}:root'
Action:
- 'kms:Encrypt'
- 'kms:Decrypt'
- 'kms:ReEncrypt*'
- 'kms:GenerateDataKey*'
- 'kms:DescribeKey'
Resource: '*'
-
Sid: 'Allow DynamoDB to use the key via Lambda'
Effect: 'Allow'
Principal:
AWS: !GetAtt LambdaRole.Arn
Action:
- 'kms:Encrypt'
- 'kms:Decrypt'
- 'kms:ReEncrypt*'
- 'kms:GenerateDataKey*'
- 'kms:DescribeKey'
- 'kms:CreateGrant'
Condition:
StringLike:
kms:ViaService:
- 'dynamodb.${self:provider.region}.amazonaws.com'
Resource: '*'
DynamoKMSAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: 'alias/dynamo-${self:provider.stage}-${self:service}-key'
TargetKeyId: !Ref DynamoKMSKey
S3KMSKey:
Type: AWS::KMS::Key
Properties:
Description: !Sub 'Encrypts S3 data'
KeyPolicy:
Version: '2012-10-17'
Id: 's3-${self:provider.stage}-${self:service}-key'
Statement:
-
Sid: 'Allow root administration of the key'
Effect: 'Allow'
Principal:
AWS: 'arn:aws:iam::${env:accountNumber}:root'
Action:
- 'kms:*'
Resource: '*'
-
Sid: 'Allow root use of the key'
Effect: 'Allow'
Principal:
AWS: 'arn:aws:iam::${env:accountNumber}:root'
Action:
- 'kms:Encrypt'
- 'kms:Decrypt'
- 'kms:ReEncrypt*'
- 'kms:GenerateDataKey*'
- 'kms:DescribeKey'
Resource: '*'
-
Sid: 'Allow S3 to use the key for encryption via Lambda'
Effect: 'Allow'
Principal:
AWS: !GetAtt LambdaRole.Arn
Action:
- 'kms:Encrypt'
- 'kms:Decrypt'
- 'kms:ReEncrypt*'
- 'kms:GenerateDataKey*'
- 'kms:DescribeKey'
- 'kms:CreateGrant'
Condition:
StringLike:
kms:ViaService: 's3.${self:provider.region}.amazonaws.com'
kms:CallerAccount: '${env:accountNumber}'
Resource:
- '*'
S3KMSAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: 'alias/s3-${self:provider.stage}-${self:service}-key'
TargetKeyId: !Ref S3KMSKey
AgentDataTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: '${self:provider.stage}-${self:service}-data'
AttributeDefinitions:
- AttributeName: email
AttributeType: S
- AttributeName: captureDate
AttributeType: S
KeySchema:
- AttributeName: email
KeyType: HASH
- AttributeName: captureDate
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
SSESpecification:
KMSMasterKeyId: !Ref DynamoKMSKey
SSEEnabled: true
SSEType: KMS
S3BucketSite:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: '${self:provider.stage}-${self:service}-site-${self:provider.region}-${env:accountNumber}'
CorsConfiguration:
CorsRules:
-
AllowedOrigins:
- '*'
AllowedHeaders:
- '*'
AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
MaxAge: 3000
S3BucketData:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: '${self:provider.stage}-${self:service}-data-${self:provider.region}-${env:accountNumber}'
CorsConfiguration:
CorsRules:
-
AllowedOrigins:
- '*'
AllowedHeaders:
- '*'
AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
MaxAge: 3000
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: 'aws:kms'
KMSMasterKeyID: !GetAtt S3KMSKey.Arn
BucketKeyEnabled: true