forked from huksley/todo-react-ssr-serverless
-
Notifications
You must be signed in to change notification settings - Fork 4
/
serverless.yml
133 lines (128 loc) · 3.55 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
# For full config options, check the docs:
# docs.serverless.com
service: todo
provider:
name: aws
runtime: nodejs12.x
region: ${env:AWS_REGION, 'us-east-1'}
stage: dev
stackTags:
STACK: "todo"
# optional, in MB, default is 1024, min 128
memorySize: 128
# optional, in seconds, default is 6
timeout: 6
# optional, default is true
versionFunctions: false
# IAM custom roles
iamRoleStatements:
# Allow access to CloudWatch logs for lambdas in role
- 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/*:*:*'
# Define additional env vars for deployment
environment:
TODO_TABLE: ${self:custom.todoTable}
API_URL: ${self:custom.apiUrlByCustomDomain.${env:CUSTOM_DOMAIN_ENABLED, 'false'}}
ASTRA_SECURE_BUNDLE_ZIP: ${env:ASTRA_SECURE_BUNDLE_ZIP, '/opt/secure-connect-todolist.zip'}
ASTRA_KEYSPACE: ${env:ASTRA_KEYSPACE, 'todolist'}
ASTRA_USERNAME: ${env:ASTRA_USERNAME, 'todolist'}
ASTRA_PASSWORD: ${env:ASTRA_PASSWORD, 'todolist'}
PUBLIC_PATH: ${env:PUBLIC_PATH}, ''}
custom:
todoTable: 'todos'
# If set, CDN bucket will be created
cdnBucketName: ${env:CDN_BUCKET, 'todo-dev-cdn-bucket'}
# Set API_URL by custom domain here
apiUrlByCustomDomain:
true: https://${env:CUSTOM_DOMAIN, 'custom.domain.serverless.com'}/api
false: ${env:PUBLIC_PATH, ''}/api
# Make special webpack transpiling for Serverless
webpack:
webpackConfig: ./webpack.serverless.js
includeModules: true
packager: 'npm'
# Create custom domain and serve it using https://$CUSTOM_DOMAIN/* -> <api endpoint>/*
customDomain:
domainName: ${env:CUSTOM_DOMAIN, 'custom.domain.serverless.com'}
createRoute53Record: true
enabled: ${env:CUSTOM_DOMAIN_ENABLED, 'false'}
# Add binary images as handled in API gateway
apigwBinary:
types:
- 'image/*'
- 'application/font*'
- 'application/pdf'
s3Sync:
- bucketName: ${self:custom.cdnBucketName, 'undefined'}
localDir: ./dist
acl: public-read
followSymlinks: true
defaultContentType: application/octet-stream
params:
- "*.*":
CacheControl: 'no-cache'
package:
exclude:
- tmp/**
- node_modules/aws_sdk/**
functions:
app:
handler: server.serverless
layers:
- {Ref: AstraLambdaLayer}
events:
- http: ANY /
- http: 'ANY {proxy+}'
- http:
# List all todos
path: api/todo/{any+}
method: get
- http:
# Add new todo
path: api/todo/{any+}
method: post
- http:
# Update todo
path: api/todo/{any+}
method: delete
- http:
# Reinit todo db
path: api/init
method: post
plugins:
- serverless-webpack
- serverless-domain-manager
- serverless-apigw-binary
- serverless-offline
- serverless-s3-sync
layers:
astra:
path: astra
resources:
Conditions:
CreateCdnBucket:
Fn::Not:
- Fn::Equals:
- ${self:custom.cdnBucketName, ''}
- ''
Resources:
CdnBucket:
Type: AWS::S3::Bucket
Condition: CreateCdnBucket
Properties:
BucketName: ${self:custom.cdnBucketName, 'undefined'}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html