-
Notifications
You must be signed in to change notification settings - Fork 7
/
serverless.yml
228 lines (221 loc) · 6.92 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
service: nuxt-serverless-at-edge
provider:
name: aws
runtime: nodejs10.x
region: us-east-1
logRetentionInDays: 3
iamRoleStatements:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- 'Fn::Join':
- ':'
-
- 'arn:aws:logs'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'log-group:/aws/lambda/*:*:*'
- Effect: Allow
Action:
- s3:PutObject
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::"
- "Ref" : "ServerlessDeploymentBucket"
plugins:
- serverless-plugin-cloudfront-lambda-edge
- serverless-scriptable-plugin
custom:
scriptHooks:
before:package:createDeploymentArtifacts: npm run build
before:invoke:local:invoke: npm run build
before:deploy:deploy:
- aws s3 cp --recursive ./.nuxt/dist/client/ s3://nuxt-serverless-at-edge/_nuxt/ --cache-control "max-age=31536000,public,immutable"
- aws s3 cp --recursive ./static/ s3://nuxt-serverless-at-edge/ --exclude "README.md" --cache-control "max-age=31536000,public,immutable"
#after:deploy:finalize: aws cloudfront create-invalidation --distribution-id ${cf:nuxt-serverless-at-edge-dev.NuxtEdgeDistributionId} --paths "/*"
package:
individually: true
excludeDevDependencies: true
functions:
render:
handler: server/edge.handler
memorySize: 512
timeout: 10
lambdaAtEdge:
distribution: 'NuxtEdgeDistribution'
eventType: 'origin-request'
package:
exclude:
- "assets/**"
- "components/**"
- "layouts/**"
- "components/**"
- "middleware/**"
- "pages/**"
- "plugins/**"
include:
- ".nuxt/**"
- "server/edge.js"
- "nuxt.config.js"
resources:
Resources:
NuxtEdgeBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: nuxt-serverless-at-edge
NuxtEdgeBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: { Ref: NuxtEdgeBucket }
PolicyDocument:
Statement:
-
Action:
- "s3:GetObject"
Effect: Allow
Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { Ref : NuxtEdgeBucket }, "/*" ] ] }
Principal:
AWS: { "Fn::Join" : [" ", ["arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity", { Ref: NuxtEdgeOriginAccessIdentity } ] ] }
NuxtEdgeOriginAccessIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: "CloudFrontOriginAccessIdentity for ${self:service}-${self:provider.stage}"
NuxtEdgeDistribution:
Type: 'AWS::CloudFront::Distribution'
Properties:
DistributionConfig:
DefaultCacheBehavior:
TargetOriginId: 'NuxtEdgeBucketOrigin'
ViewerProtocolPolicy: 'redirect-to-https'
MinTTL: 0
DefaultTTL: 0
MaxTTL: 0
Compress: true
ForwardedValues:
QueryString: true
AllowedMethods:
- GET
- HEAD
- OPTIONS
- PUT
- POST
- PATCH
- DELETE
DefaultRootObject: ''
Enabled: true
PriceClass: 'PriceClass_100'
HttpVersion: 'http2'
IPV6Enabled: false
Origins:
-
Id: 'NuxtEdgeBucketOrigin'
DomainName: { 'Fn::GetAtt': [ NuxtEdgeBucket, DomainName ] }
S3OriginConfig:
OriginAccessIdentity: { "Fn::Join" : ["", ["origin-access-identity/cloudfront/", { Ref: NuxtEdgeOriginAccessIdentity } ] ] }
CacheBehaviors:
- PathPattern: '*.jpg'
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: NuxtEdgeBucketOrigin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: 'https-only'
MinTTL: 31536000
DefaultTTL: 31536000
MaxTTL: 31536000
Compress: true
- PathPattern: '*.css'
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: NuxtEdgeBucketOrigin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: 'https-only'
MinTTL: 31536000
DefaultTTL: 31536000
MaxTTL: 31536000
Compress: true
- PathPattern: '*.js'
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: NuxtEdgeBucketOrigin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: 'https-only'
MinTTL: 31536000
DefaultTTL: 31536000
MaxTTL: 31536000
Compress: true
- PathPattern: '*.map'
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: NuxtEdgeBucketOrigin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: 'https-only'
MinTTL: 31536000
DefaultTTL: 31536000
MaxTTL: 31536000
Compress: true
- PathPattern: '*.ico'
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: NuxtEdgeBucketOrigin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: 'https-only'
MinTTL: 31536000
DefaultTTL: 31536000
MaxTTL: 31536000
Compress: true
- PathPattern: '*.png'
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: NuxtEdgeBucketOrigin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: 'https-only'
MinTTL: 31536000
DefaultTTL: 31536000
MaxTTL: 31536000
Compress: true
Outputs:
NuxtEdgeDistributionDomain:
Value:
'Fn::GetAtt': [ NuxtEdgeDistribution, DomainName ]
Export:
Name: NuxtEdgeDistributionDomain
NuxtEdgeDistributionId:
Value:
Ref: NuxtEdgeDistribution
Export:
Name: NuxtEdgeDistributionId