-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
382 lines (352 loc) · 12 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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
service: ${env:STACK_NAME}-${env:ROOTSTACK}
frameworkVersion: '2'
useDotenv: true
package:
include:
- artifacts/**/*
- serverless.yml
- .env
- package.json
- package-lock.json
provider:
logRetentionInDays: 365 # Set the default RetentionInDays for a CloudWatch LogGroup
name: aws
runtime: nodejs14.x
timeout: 30
memorySize: 128
region: ${env:REGION}
stage: ${env:ENV}
lambdaHashingVersion: 20201221
deploymentBucket:
blockPublicAccess: true
serverSideEncryption: AES256
tags:
StackName: ${env:STACK_NAME}
Env: ${env:ENV}
stackTags: # Optional CF stack tags
StackName: ${env:STACK_NAME}
Env: ${env:ENV}
tags: # Optional service wide function tags
StackName: ${env:STACK_NAME}
Env: ${env:ENV}
tracing:
lambda: true
vpc:
securityGroupIds: !Split [",", "${env:SECURITYGP}"]
subnetIds: !Split [",", "${env:PRIVATESUBNET}"]
iam:
role:
statements:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:DeleteLogGroup
- logs:PutLogEvents
- logs:DescribeLogStreams
- logs:DescribeLogGroups
- logs:FilterLogEvents
Resource: "arn:aws:logs:*:*:*"
- Effect: Allow
Action:
- lambda:AddPermission
- lambda:CreateAlias
- lambda:DeleteFunction
- lambda:InvokeFunction
- lambda:PublishVersion
- lambda:RemovePermission
- lambda:Update*
Resource:
- arn:aws:lambda:*:*:function:*
- Effect: Allow
Action:
- apigateway:GET
- apigateway:POST
- apigateway:PUT
- apigateway:DELETE
- apigateway:PATCH
Resource:
- arn:aws:apigateway:*::/restapis*
- arn:aws:apigateway:*::/apikeys*
- arn:aws:apigateway:*::/usageplans*
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
- ssm:*
Resource:
- arn:aws:secretsmanager:*:*:secret:*
- Effect: "Allow" # xray permissions (required)
Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Resource:
- "*"
- Effect: Allow
Action:
- ec2:CreateNetworkInterface
- ec2:AttachNetworkInterface
- ec2:DescribeNetworkInterfaces
- ec2:DetachNetworkInterface
- ec2:DeleteNetworkInterface
- ec2:DescribeSecurityGroups
- ec2:DescribeSubnets
- ec2:DescribeVpcs
Resource: '*'
- Effect: Allow
Action:
- s3:*
Resource: 'arn:aws:s3:::${env:FILEAPIS3BUCKET}/*'
functions:
services:
handler: src/index.handler
description: ${env:STACK_NAME}-${env:ROOTSTACK}-lambda
plugins:
- serverless-plugin-aws-alerts
- serverless-offline
- serverless-plugin-typescript
custom:
serverless-offline:
host: 0.0.0.0
alerts:
stages:
- live
- test
- dev
topics:
alarm:
topic: {'Fn::ImportValue': !Sub '${env:STACK_NAME}-ChatBotSNSTopicARN-${env:ENV}'}
definitions: # these defaults are merged with your definitions
functionErrors:
namespace: 'AWS/Lambda'
metric: Errors
threshold: 5
statistic: Sum
period: 180
evaluationPeriods: 3
datapointsToAlarm: 3
comparisonOperator: GreaterThanOrEqualToThreshold
treatMissingData: notBreaching # override treatMissingData
functionThrottles:
namespace: 'AWS/Lambda'
metric: Throttles
threshold: 5
statistic: Sum
period: 180
evaluationPeriods: 3
datapointsToAlarm: 3
comparisonOperator: GreaterThanOrEqualToThreshold
treatMissingData: notBreaching # override treatMissingData
functionInvocations:
namespace: 'AWS/Lambda'
metric: Invocations
threshold: 1000
statistic: Sum
period: 180
evaluationPeriods: 3
datapointsToAlarm: 3
comparisonOperator: GreaterThanOrEqualToThreshold
treatMissingData: notBreaching # override treatMissingData
functionDuration:
namespace: 'AWS/Lambda'
metric: Duration
threshold: 28000 # 28 seconds
statistic: 'p99'
period: 180
evaluationPeriods: 3
datapointsToAlarm: 3
comparisonOperator: GreaterThanOrEqualToThreshold
treatMissingData: notBreaching # override treatMissingData
evaluateLowSampleCountPercentile: ignore
CustomMetricFilter:
metric: CustomMetricFilterError
threshold: 5
statistic: Sum
period: 180
evaluationPeriods: 3
datapointsToAlarm: 3
comparisonOperator: GreaterThanOrEqualToThreshold
pattern: 'ERROR'
treatMissingData: notBreaching # override treatMissingData
alarms:
- functionErrors
- functionThrottles
- functionInvocations
- functionDuration
- CustomMetricFilter
resources:
Resources:
## Specifying the CloudFront Origin Access Identity CDN Distribution to server your Web Application
FileApiCloudFrontOriginAccessIdentity:
Type: 'AWS::CloudFront::CloudFrontOriginAccessIdentity'
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: "Cloudfront Origin identity for ${env:FILEAPIS3BUCKET}"
## Specifying the CloudFront Distribution to server your Web Application
FileApiCloudFrontDistribution:
DependsOn: [FileApiCloudFrontSecurityHeaderResponse]
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Aliases:
- ${env:FILEAPIS3BUCKET}
Comment: "Cloudfront Origin identity for ${env:FILEAPIS3BUCKET}"
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
- PUT
- POST
- PATCH
- DELETE
CachedMethods:
- GET
- HEAD
- OPTIONS
Compress: true
DefaultTTL: 3600 # in seconds
ForwardedValues:
Cookies:
Forward: none
QueryString: false
MaxTTL: 86400 # in seconds
MinTTL: 60 # in seconds
TargetOriginId: ${env:FILEAPIS3BUCKET}
ViewerProtocolPolicy: 'redirect-to-https'
ResponseHeadersPolicyId: !Ref FileApiCloudFrontSecurityHeaderResponse
# DefaultRootObject: index.html
CustomErrorResponses:
- ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /index.html #TBD
- ErrorCode: 403
ResponseCode: 200
ResponsePagePath: /index.html #TBD
Enabled: true
HttpVersion: http2
IPV6Enabled: true
Origins:
- DomainName: '${env:FILEAPIS3BUCKET}.s3.amazonaws.com'
Id: ${env:FILEAPIS3BUCKET}
S3OriginConfig:
OriginAccessIdentity: !Sub 'origin-access-identity/cloudfront/${FileApiCloudFrontOriginAccessIdentity}'
PriceClass: 'PriceClass_All'
ViewerCertificate:
AcmCertificateArn: '${env:CDNSharedACMCertificateArn}'
MinimumProtocolVersion: 'TLSv1.2_2021' # OLD VALUE:'TLSv1.2_2019'
SslSupportMethod: 'sni-only'
# Specifying the CloudFront Distribution Security Response Header
FileApiCloudFrontSecurityHeaderResponse:
Type: AWS::CloudFront::ResponseHeadersPolicy
Properties:
ResponseHeadersPolicyConfig:
Comment: "practera-security-headers-for-${env:FILEAPIS3BUCKET}"
Name: "practera-security-headers-for-FileApi"
SecurityHeadersConfig:
StrictTransportSecurity:
AccessControlMaxAgeSec: 31536000
IncludeSubdomains: true
Override: true
Preload: true
# ContentSecurityPolicy:
# ContentSecurityPolicy: "frame-ancestors 'self' https://*.practera.com;"
# Override: true
# ContentTypeOptions:
# Override: true
# ReferrerPolicy:
# ReferrerPolicy: "strict-origin-when-cross-origin"
# Override: true
# XSSProtection:
# ModeBlock: true
# Override: true
# Protection: true
# CustomHeadersConfig:
# Items:
# -
# Header: "Server"
# Override: true
# Value: "Server"
# -
# Header: "Permissions-Policy"
# Override: true
# Value: "accelerometer=(),camera=(),geolocation=(),gyroscope=(),magnetometer=(),microphone=(),payment=(),usb=()"
# Security Header Response CFN END
## Specifying the policies to make sure all files inside the Bucket are avaialble to CloudFront
FileApiS3BucketPolicy:
DependsOn: [FileApiCloudFrontOriginAccessIdentity]
Type: AWS::S3::BucketPolicy
Properties:
Bucket: ${env:FILEAPIS3BUCKET}
PolicyDocument:
Statement:
- Sid: S3-Bucket-Accesible via CDN OAI only
Action: 's3:*'
Effect: Allow
Resource: 'arn:aws:s3:::${env:FILEAPIS3BUCKET}/*'
Principal:
CanonicalUser: !GetAtt FileApiCloudFrontOriginAccessIdentity.S3CanonicalUserId
- Sid: AllowSSLRequestsOnly # AWS Foundational Security Best Practices v1.0.0 S3.5
Effect: Deny
Principal: '*'
Action: 's3:*'
Resource:
- 'arn:aws:s3:::${env:FILEAPIS3BUCKET}'
- 'arn:aws:s3:::${env:FILEAPIS3BUCKET}/*'
Condition:
Bool:
'aws:SecureTransport': false
- Sid: S3-Bucket-Accesible to filestack uploads
Action:
- 's3:PutObjectAcl'
- 's3:PutObject'
- 's3:GetObject'
Effect: Allow
Resource:
- 'arn:aws:s3:::${env:FILEAPIS3BUCKET}'
- 'arn:aws:s3:::${env:FILEAPIS3BUCKET}/*'
Principal:
AWS:
- 'arn:aws:iam::${env:FILESTACKAWSID}:user/filestack-uploads'
# - Sid: S3-Bucket-Accesible to main practera account
# Action:
# - 's3:PutObjectAcl'
# - 's3:PutObject'
# - 's3:GetObject'
# Effect: Allow
# Resource:
# - 'arn:aws:s3:::${env:FILEAPIS3BUCKET}'
# - 'arn:aws:s3:::${env:FILEAPIS3BUCKET}/*'
# Principal:
# AWS:
# - 'arn:aws:iam::${env:P1STACKAWSID}:user/practera'
Route53RecordV2:
Type: 'AWS::Route53::RecordSetGroup'
Properties:
HostedZoneId: {'Fn::ImportValue': '${env:STACK_NAME}-PublicHostedZoneId-${env:ENV}'}
RecordSets:
- Name: ${env:FILEAPIS3BUCKET}
Type: CNAME
TTL: '3200'
ResourceRecords:
- !GetAtt 'FileApiCloudFrontDistribution.DomainName'
Outputs:
FileApiCloudFrontDistributionOutput:
Value:
'Fn::GetAtt': [ FileApiCloudFrontDistribution, DomainName ]
Export:
Name: ${env:STACK_NAME}-FileApiCloudFrontDistributionOutput-${env:ENV}
FileApiS3BucketURL:
Description: 'URL to static website.'
Value: https://${env:FILEAPIS3BUCKET}
Export:
Name: ${env:STACK_NAME}-FileApiS3BucketURL-${env:ENV}
FileApiCloudFrontDistributionID:
Description: 'CloudFront distribution id'
Value: !Ref FileApiCloudFrontDistribution
Export:
Name: ${env:STACK_NAME}-FileApiCloudFrontDistributionID-${env:ENV}
FileApiS3Bucket:
Description: 'Name of the S3 bucket storing the static files.'
Value: '${env:FILEAPIS3BUCKET}'
Export:
Name: ${env:STACK_NAME}-FileApiS3Bucket-${env:ENV}