forked from laardee/one-time-presigned-url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
140 lines (135 loc) · 4 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
service: presigned-upload # change this
provider:
name: aws
runtime: nodejs8.10
region: us-east-1 # lambda@edge functions & cloudfront needs to be deployed to us-east-1
iamRoleStatements:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- arn:aws:logs:*:*:* # allow replicated lambdas to create logs
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:ListBucket
- s3:ListBucketVersions
Resource:
- 'arn:aws:s3:::${self:custom.config.bucket}'
- 'arn:aws:s3:::${self:custom.config.bucket}/*'
functions:
url:
handler: url/index.handler
memorySize: 128
timeout: 5
lambdaAtEdge:
distribution: CloudFront
eventType: viewer-request
pathPattern: 'url'
validate:
handler: validate/index.handler
memorySize: 128
timeout: 5
lambdaAtEdge:
distribution: CloudFront
eventType: viewer-request
plugins:
- '@silvermine/serverless-plugin-cloudfront-lambda-edge'
custom:
stage: ${opt:stage, self:provider.stage}
config: ${file(./config.json)} # config json has shared parameters -> Lambda@Edge doesn't support Lambda environmental variables
serverless-iam-roles-per-function:
defaultInherit: true
resources:
Resources:
Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.config.bucket}
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
VersioningConfiguration:
Status: Enabled
CorsConfiguration:
CorsRules:
- AllowedHeaders: ['*']
AllowedMethods: [GET, PUT]
AllowedOrigins: ['*']
Id: CORSRuleId1
MaxAge: '3600'
CloudFront:
Type: AWS::CloudFront::Distribution
DependsOn: Bucket
Properties:
DistributionConfig:
Enabled: true
Comment: '${self:custom.stage}-${self:service}'
PriceClass: PriceClass_100
HttpVersion: http2
IPV6Enabled: true
ViewerCertificate:
CloudFrontDefaultCertificate: true
CustomErrorResponses:
- ErrorCachingMinTTL: 0
ErrorCode: 400
- ErrorCachingMinTTL: 0
ErrorCode: 403
- ErrorCachingMinTTL: 0
ErrorCode: 404
- ErrorCachingMinTTL: 0
ErrorCode: 405
- ErrorCachingMinTTL: 0
ErrorCode: 414
- ErrorCachingMinTTL: 0
ErrorCode: 416
- ErrorCachingMinTTL: 0
ErrorCode: 500
- ErrorCachingMinTTL: 0
ErrorCode: 501
- ErrorCachingMinTTL: 0
ErrorCode: 502
- ErrorCachingMinTTL: 0
ErrorCode: 503
- ErrorCachingMinTTL: 0
ErrorCode: 504
Origins:
- DomainName: ${self:custom.config.bucket}.s3.amazonaws.com
Id: S3Origin
S3OriginConfig: {}
DefaultCacheBehavior:
TargetOriginId: S3Origin
ViewerProtocolPolicy: redirect-to-https
DefaultTTL: 0
MaxTTL: 0
MinTTL: 0
ForwardedValues:
QueryString: 'true'
Cookies:
Forward: none
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
CacheBehaviors:
- TargetOriginId: S3Origin
ViewerProtocolPolicy: redirect-to-https
DefaultTTL: 0
MaxTTL: 0
MinTTL: 0
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
PathPattern: 'url'
AllowedMethods:
- GET
- HEAD