-
Notifications
You must be signed in to change notification settings - Fork 16
/
serverless.yml
126 lines (115 loc) · 3.17 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
service: 'sveltekit-app'
frameworkVersion: "2"
plugins:
- '@silvermine/serverless-plugin-cloudfront-lambda-edge'
- serverless-s3-deploy
provider:
name: aws
runtime: nodejs14.x
lambdaHashingVersion: 20201221
region: us-east-1
stage: ${opt:stage, 'dev'}
package:
individually: true
exclude:
- ./**
include:
- build/server/**
- build/edge/**
custom:
assets:
auto: true
targets:
- bucket:
Ref: StaticAssets
files:
- source: ./build/assets/
globs:
- '**'
empty: true
headers:
CacheControl: max-age=31104000
- source: ./build/prerendered/
globs:
- '**'
empty: true
headers:
CacheControl: max-age=60
functions:
#SSR Function
svelte:
handler: build/server/serverless.handler
memorySize: 256
timeout: 15
events:
- http: ANY /
- http: ANY /{proxy+}
#Router Function
cfLambda:
handler: build/edge/router.handler
memorySize: 128
timeout: 1
lambdaAtEdge:
distribution: 'WebsiteDistribution'
eventType: origin-request
resources:
Resources:
StaticAssets:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
BucketName: ${self:provider.stage}-${self:service}-static-assets
StaticAssetsS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: StaticAssets
PolicyDocument:
Statement:
- Sid: PublicReadGetObject
Effect: Allow
Principal: "*"
Action:
- s3:GetObject
Resource:
Fn::Join: ["", ["arn:aws:s3:::", { "Ref": "StaticAssets" }, "/*"]]
WebsiteDistribution:
Type: 'AWS::CloudFront::Distribution'
Properties:
DistributionConfig:
Origins:
-
DomainName: { "Fn::Join" : ["", [{ "Ref" : "ApiGatewayRestApi" }, ".execute-api.${self:provider.region}.amazonaws.com" ] ] }
OriginPath: /${self:provider.stage}
Id: default
OriginCustomHeaders:
#Lambda@edge does not support ENV vars, so instead we have to pass in a customHeaders.
-
HeaderName: 's3-host'
HeaderValue: '${self:provider.stage}-${self:service}-static-assets.s3.amazonaws.com'
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: 'https-only'
Enabled: true
Comment: '${self:service}_${self:provider.stage}'
DefaultCacheBehavior:
TargetOriginId: default
Compress: true
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
CachedMethods:
- GET
- HEAD
- OPTIONS
ForwardedValues:
Cookies:
Forward: all
QueryString: True
ViewerProtocolPolicy: 'redirect-to-https'