This repository was archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathserverless.yml
More file actions
192 lines (175 loc) · 7.2 KB
/
serverless.yml
File metadata and controls
192 lines (175 loc) · 7.2 KB
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
# CloudFormation output name: `sls-${SERVICE_NAME}-${STAGE}`
service: sls-${self:custom.service}
custom:
service: ${env:SERVICE_NAME}
region: ${opt:region, env:AWS_REGION}
stage: ${opt:stage, env:STAGE}
jetpack:
preInclude:
- "!**" # Start with no files at all.
trace:
# Use trace mode for speed and ignore aws-sdk + all deps
ignores:
- "aws-sdk"
plugins:
- serverless-jetpack
- serverless-offline
- serverless-plugin-canary-deployments
provider:
name: aws
# Required: import the default role that terraform-aws-serverless generates.
role:
Fn::ImportValue: tf-${self:custom.service}-${self:custom.stage}-LambdaExecutionRoleArn
# OPTION(custom_role): terraform-aws-serverless lets you provide a custom
# IAM role in place of its autogenerated one. If you provide a custom role,
# expose it as an export on a CloudFormation stack and import it like so:
# Fn::ImportValue: tf-${self:custom.service}-${self:custom.stage}-LambdaExecutionRoleCustomArn
# Lambda configuration
runtime: nodejs12.x
timeout: 30 # seconds (`300` max)
memorySize: 128 # MB value (`1024` default)
# Deployment / environment configuration
region: ${self:custom.region}
stage: ${self:custom.stage}
environment:
STAGE: ${self:custom.stage}
SERVICE_NAME: ${self:custom.service}
# AWS Resource Tags: Match terraform module
stackTags: # For CF stack
Stage: ${self:custom.stage}
Service: ${self:custom.service}
tags: # For resources
Stage: ${self:custom.stage}
Service: ${self:custom.service}
functions:
# SCENARIO - base: The simplest, vanilla Serverless app.
base:
handler: src/server/base.handler
events: # Use a generic proxy to allow Express app to route.
- http: ANY /base
- http: 'ANY /base/{proxy+}'
###############################################################################
# OPTIONAL STUFF BELOW!!!
# =======================
# Everything below here provides specific features and enhancements that you
# may wish to investigate in a serverless app, such as:
# - `xray`: Set up AWS Xray tracing
# - `vpc`: Deploy Lambda in AWS VPC
# - `layers`: Deploy Lambda Layers alongside Lambda Functions
###############################################################################
#############################################################################
# OPTION(xray): Simple app with Xray tracing.
#############################################################################
xray:
handler: src/server/xray.handler
events:
- http: ANY /xray
- http: 'ANY /xray/{proxy+}'
#############################################################################
# OPTION(vpc): Our vanilla app, but in a VPC
#############################################################################
vpc:
handler: src/server/base.handler
events:
- http: ANY /vpc
- http: 'ANY /vpc/{proxy+}'
environment:
BASE_URL: /vpc
# VPC: Add in SGs and SNs.
# https://serverless.com/framework/docs/providers/aws/guide/functions#vpc-configuration
vpc:
securityGroupIds:
- Fn::ImportValue: "tf-${self:custom.service}-${self:custom.stage}-VPCSecurityGroupId"
subnetIds:
- Fn::ImportValue: "tf-${self:custom.service}-${self:custom.stage}-VPCPrivateSubnetA"
- Fn::ImportValue: "tf-${self:custom.service}-${self:custom.stage}-VPCPrivateSubnetB"
#############################################################################
# OPTION(canary): Canary-deployed Lambda using serverless-plugin-canary-deployments
# To watch the canary deploy's progress for the sandbox environment, view its
# CodeDeploy project here:
# https://us-east-1.console.aws.amazon.com/codesuite/codedeploy/applications/sls-simple-reference-sandbox-SlssimplereferencesandboxDeploymentApplication-LI2MS1UTYKZT?region=us-east-1
#
# To view canary progress for other stages, find them in CodeDeploy Applications:
# https://us-east-1.console.aws.amazon.com/codesuite/codedeploy/applications?region=us-east-1
#############################################################################
canary:
handler: src/server/base.handler
events: # Use a generic proxy to allow Express app to route.
- http: ANY /canary
- http: 'ANY /canary/{proxy+}'
environment:
BASE_URL: /canary
deploymentSettings:
# See all options here: https://github.com/davidgf/serverless-plugin-canary-deployments#configuration
type: AllAtOnce
alias: Live
#############################################################################
# OPTION(layers): Conditional import can use code from a layer.
#
# **Localdev**:
# ```sh
# # Can't find deps
# $ STAGE=sandbox yarn lambda:localdev
# $ curl http://127.0.0.1:3001/layers/layers.txt
# Could not import figlet via layers. Sorry, no ASCII art today... :(
#
# # Hack in deps sort-of-equivalent to deployed.
# $ NODE_PATH="${NODE_PATH}:./layers/vendor/nodejs/node_modules" STAGE=sandbox yarn lambda:localdev
# $ curl http://127.0.0.1:3001/layers/layers.txt
# _ _ _ _ _ _ _ _
# | | | | ___| | | ___ | | __ _ _ _ ___ _ __ ___| | | |
# | |_| |/ _ \ | |/ _ \ | | / _` | | | |/ _ \ '__/ __| | | |
# | _ | __/ | | (_) | | |__| (_| | |_| | __/ | \__ \_|_|_|
# |_| |_|\___|_|_|\___/ |_____\__,_|\__, |\___|_| |___(_|_|_)
# |___/
# ```
#############################################################################
layers:
handler: src/server/layers.handler
events:
- http: ANY /layers
- http: 'ANY /layers/{proxy+}'
environment:
BASE_URL: /layers
layers:
- { Ref: VendorLambdaLayer }
- { Ref: RepeatLambdaLayer }
# Package individually for function-level tracing ignores / options.
# Easier general solution is no tracing when layer dependencies, although
# tracing is likely faster and slimmer.
package:
individually: true
jetpack:
trace:
ignores: # Add ignores for things provided by layers.
- "figlet" # From VendorLambdaLayer
- "/opt" # From RepeatLambdaLayer
###############################################################################
# OPTION(layers): Add some layers.
###############################################################################
layers:
# Dependencies: Adds common vendor libs to a `node_modules` directory.
# Note: Expands to `/opt/nodejs/node_modules/**/*.js`, so should only do this once.
vendor:
path: layers/vendor
name: sls-${self:custom.service}-${self:custom.stage}-vendor
jetpack:
roots:
- layers/vendor/nodejs
# No dependencies: A vanilla JS function.
# Note: Expands to `/opt/repeat/*.js` (we have `layers/repeat/repeat` here).
repeat:
path: layers/repeat
name: sls-${self:custom.service}-${self:custom.stage}-repeat
package:
include:
- "repeat/*.js"
resources:
Resources:
###########################################################################
# OPTION(Xray): Enable Xray tracing.
###########################################################################
XrayLambdaFunction:
Properties:
TracingConfig:
Mode: Active