forked from jamesladd/aws-vite-ssr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
138 lines (128 loc) · 3.68 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
service: aws-vite-ssr
frameworkVersion: '2'
plugins:
- serverless-domain-manager
- serverless-api-gateway-caching
provider:
name: aws
runtime: nodejs14.x
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'us-east-1'}
versionFunctions: false
lambdaHashingVersion: 20201221
apiGateway:
shouldStartNameWithService: true
environment: ${file(env.yml):${self:provider.stage}}
package:
exclude:
- static/**
custom:
env: ${self:provider.environment}
customDomain:
domainName: ${self:custom.env.APP_DOMAIN}
certificateName: ${self:custom.env.APP_CERTIFICATE_NAME}
createRoute53Record: true
endpointType: 'regional'
securityPolicy: tls_1_2
apiType: rest
autoDomain: true
enabled: true
functions:
ssr:
handler: server/ssr.handler
reservedConcurrency: 4
timeout: 30
role: SsrRoleV1
events:
- http:
path: /
method: any
caching:
enabled: false
- http:
path: /{proxy+}
method: any
caching:
enabled: false
resources:
Resources:
SsrCachePolicy:
Type: 'AWS::CloudFront::CachePolicy'
Properties:
CachePolicyConfig:
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 1
Name: ${self:service}-${self:provider.stage}-cf-policy
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: 'all'
EnableAcceptEncodingBrotli: true
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: 'none'
# Headers:
# - Host
QueryStringsConfig:
QueryStringBehavior: 'all'
SsrDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Comment: ${self:provider.stage} ${self:service}
DefaultCacheBehavior:
TargetOriginId: ${self:service}-${self:provider.stage}-Origin
ViewerProtocolPolicy: 'redirect-to-https'
CachePolicyId: !Ref SsrCachePolicy
DefaultTTL: 30
AllowedMethods:
- 'GET'
- 'HEAD'
- 'OPTIONS'
- 'PUT'
- 'PATCH'
- 'POST'
- 'DELETE'
CachedMethods:
- 'HEAD'
- 'GET'
- 'OPTIONS'
Enabled: true
Origins:
- Id: ${self:service}-${self:provider.stage}-Origin
DomainName:
Fn::Join:
- ""
- - "Ref": "ApiGatewayRestApi"
- ".execute-api.${self:provider.region}.amazonaws.com"
OriginPath: /dev
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
SsrRoleV1:
Type: AWS::IAM::Role
Properties:
RoleName: ${self:service}-${self:provider.stage}-SsrRoleV1
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
- Effect: Allow
Principal:
Service:
- edgelambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: ${self:service}-${self:provider.stage}-SsrPolicyV1
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: "Allow"
Action:
- logs:*
Resource: "*"