/
serverless.yml
112 lines (104 loc) · 2.57 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
# Name of the service
service: sls-todo-api
# Plugins enhancing serverless framework
plugins:
# Locally dynamodb for local invokation and testing
- serverless-dynamodb-local
# Offline plugin for local development and testing
- serverless-offline
custom:
# Offline plugin configuration
serverless-offline:
port: 4000
# Local dynamodb configuration
dynamodb:
start:
port: 9000
inMemory: true
migrate: true
seed: true
# Seed data for local todo table
seed:
todo:
sources:
- table: ${self:service}-todo-store
sources: [./offline/seeds/data.json]
# Configure AWS as provider
provider:
name: aws
runtime: nodejs6.10
# Name of dynamo db table used to store ToDos
environment:
TODOS_TABLE: ${self:service}-todo-store
# Roles required to operate on the dynamo db table
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:eu-central-1:*:table/${self:provider.environment.TODOS_TABLE}"
# Configured as a dev stage
stage: dev
# Chosen AWS Region
region: eu-central-1
# FaaS funtions
functions:
create:
handler: todos/create.create
# Configuring HTTP events to link API Gateway to Lambda
events:
- http:
path: todos
method: POST
cors: true
get:
handler: todos/get.get
events:
- http:
path: todos/{id}
method: GET
cors: true
update:
handler: todos/update.update
events:
- http:
path: todos/{id}
method: PUT
cors: true
delete:
handler: todos/delete.delete
events:
- http:
path: todos/{id}
method: DELETE
cors: true
list:
handler: todos/list.list
events:
- http:
path: todos
method: GET
cors: true
# Confiure the resources required for this service: AWS Dynamo DB Table
resources:
Resources:
TodoTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.TODOS_TABLE}