-
Notifications
You must be signed in to change notification settings - Fork 31
/
serverless.yml
175 lines (168 loc) · 4.5 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
# For full config options, check the docs:
# docs.serverless.com
service: todo
provider:
name: aws
runtime: nodejs8.10
region: ${env:AWS_REGION, 'eu-west-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 DynamoDB in role
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- { "Fn::GetAtt": [ "TodoDynamoDBTable", "Arn" ] }
# Allow publishing message in our own queue
- Effect: Allow
Action:
- sqs:GetQueueAttributes
- sqs:SendMessage
- sqs:DeleteMessage
- sqs:ReceiveMessage
- sqs:GetQueueUrl
Resource:
- { "Fn::GetAtt": [ "TodoEventQueue", "Arn" ] }
# Define additional env vars for deployment
environment:
TODO_TABLE: ${self:custom.todoTable}
TODO_EVENT_QUEUE: ${self:custom.todoEventQueue}
API_URL: ${self:custom.apiUrlByCustomDomain.${env:CUSTOM_DOMAIN_ENABLED, 'false'}}
custom:
todoTable: 'todos'
todoEventQueue: 'todos-events'
# If set, CDN bucket will be created
cdnBucketName: ${env:CDN_BUCKET, ''}
# Set API_URL by custom domain here
apiUrlByCustomDomain:
true: https://${env:CUSTOM_DOMAIN, 'custom.domain.serverless.com'}/api
false: 'http://localhost:3000/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
events:
- http: ANY /
- http: 'ANY {proxy+}'
- http:
# List all todos
path: api/todo
method: get
- http:
# Get all queue
path: api/queue
method: get
- http:
# Add new todo
path: api/todo
method: post
- http:
# Get one todo
path: api/todo/{any+}
method: get
- http:
# Update 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
event:
handler: server.receiveEvent
events:
- sqs:
# Invoke function once for every message
batchSize: 1
arn:
Fn::GetAtt:
- TodoEventQueue
- Arn
plugins:
- serverless-webpack
- serverless-domain-manager
- serverless-apigw-binary
- serverless-offline
- serverless-s3-sync
resources:
Conditions:
CreateCdnBucket:
Fn::Not:
- Fn::Equals:
- ${self:custom.cdnBucketName, ''}
- ''
Resources:
TodoDynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 3
WriteCapacityUnits: 3
TableName: ${self:custom.todoTable}
TodoEventQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName: ${self:custom.todoEventQueue}
MessageRetentionPeriod: 1209600
VisibilityTimeout: 60
CdnBucket:
Type: AWS::S3::Bucket
Condition: CreateCdnBucket
Properties:
BucketName: ${self:custom.cdnBucketName, 'undefined'}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html