-
Notifications
You must be signed in to change notification settings - Fork 88
/
serverless.yml
143 lines (129 loc) · 3.65 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
---
service: serverless-react-boilerplate
frameworkVersion: "3"
useDotenv: true
variablesResolutionMode: 20210326
disabledDeprecations:
- CLI_OPTIONS_SCHEMA # some Serverless plugins haven't been updated yet and generate warnings
provider:
name: aws
runtime: nodejs12.x
region: ${opt:region, 'us-east-1'}
stage: ${opt:stage, 'dev'}
memorySize: 512
timeout: 6
logRetentionInDays: 7
lambdaHashingVersion: 20201221 # for upcoming Serverless v3
apiGateway:
shouldStartNameWithService: true # for upcoming Serverless v3
environment:
SERVERLESS_PROJECT: ${self:service}
SERVERLESS_REGION: ${self:provider.region}
SERVERLESS_STAGE: ${self:provider.stage}
APP_DIST_URL: ${self:custom.distBucketUrl.${self:provider.region}, self:custom.distBucketUrl.default}
APP_PUBLIC_URL: ${self:custom.distBucketUrl.${self:provider.region}, self:custom.distBucketUrl.default}
APIGATEWAY_URL:
Fn::Join:
- ""
- - https://
- Ref: ApiGatewayRestApi
- .execute-api.
- Ref: AWS::Region
- .amazonaws.com/
- ${self:provider.stage}
plugins:
- serverless-webpack
- serverless-plugin-scripts
- serverless-offline
- serverless-s3-deploy
functions:
serve:
# Any web request regardless of path or method will be handled by a single Lambda function
handler: handler.serve
events:
- http:
path: /
method: any
cors: true
- http:
path: /{any+}
method: any
cors: true
custom:
distBucketUrl:
us-east-1:
# us-east-1 uses a different URL format than the other regions
Fn::Join:
- ""
- - https://s3.amazonaws.com/
- Ref: DistBucket
default:
# All other regions
Fn::Join:
- ""
- - https://s3-
- Ref: AWS::Region
- .amazonaws.com/
- Ref: DistBucket
scripts:
hooks:
# Build the client-side script before packaging backend code
package:initialize: "npm run build:browser"
deploy:finalize: "npx sls s3deploy --stage ${self:provider.stage}"
webpack:
webpackConfig: "webpack.server.config.js"
assets:
# Automatically copy distribution folder to S3 stopped working; do it manually (see `scripts.hooks.deploy:finalize`)
auto: false
targets:
- bucket:
Ref: DistBucket
acl: public-read
files:
- source: dist/
headers:
CacheControl: max-age=31104000 # 1 year
globs:
- "**/*"
serverless-offline:
useChildProcesses: true
noPrependStageInUrl: true
httpPort: 3000
lambdaPort: 3002
resources:
Resources:
# Customize the API Gateway resource
ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
# Enable gzip compression
MinimumCompressionSize: 1000
# S3 Bucket for the distribution bundles
DistBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
CorsConfiguration:
CorsRules:
- AllowedHeaders:
- "*"
AllowedMethods:
- "GET"
AllowedOrigins:
- Fn::Join:
- ""
- - https://
- Ref: ApiGatewayRestApi
- .execute-api.
- Ref: AWS::Region
- .amazonaws.com
MaxAge: 3000
Outputs:
ApiGatewayRestApi:
Description: API Gateway Endpoint
Value:
Ref: ApiGatewayRestApi
DistBucket:
Description: Distribution S3 Bucket
Value:
Ref: DistBucket