-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
104 lines (98 loc) · 2.91 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
service: user-service
plugins:
- serverless-esbuild # used for compiling/packaging the Typescript code
- serverless-offline # used for local execution
- serverless-dynamodb # used for local execution with dynamodb
package:
patterns:
- 'src/**'
- '!test/**'
provider:
name: aws
runtime: nodejs18.x
region: us-west-2
stage: ${opt:stage, 'dev'}
timeout: 30
environment:
STAGE: ${self:provider.stage}
LOG_LEVEL: 'DEBUG' #${ssm:${self:provider.stage}.LOG_LEVEL}
USER_TABLE: ${self:provider.stage}.user
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:Query
- dynamodb:PutItem
Resource:
- arn:aws:dynamodb:${self:provider.region}:${self:custom.accountId}:table/${self:provider.environment.USER_TABLE}*
custom:
accountId: 9999999 #FIXME got an error when trying to resolve ${aws:accountId} with serverless offline. this must be manually set (for now)
managedTablesDeletionPolicy: # This is useful to avoid data loss when deploying changes to table key schema to production
prod: Retain
default: Delete
serverless-dynamodb:
stages:
- local
- dev
start:
docker: false
migrate: true,
seed: true
port: 8000
inMemory: true
seed:
test:
sources:
- table: ${self:provider.environment.USER_TABLE}
sources: [./test/integration/seed-data/user.data.json]
functions:
get-user:
handler: ./src/user-handlers.get
events:
- httpApi: 'GET /user/{userId}'
create-user:
handler: ./src/user-handlers.create
events:
- httpApi: 'POST /user'
# update-user:
# handler: ./src/user-handlers.update
# events:
# - httpApi: 'PUT /user/{id}'
list-users:
handler: ./src/user-handlers.list
events:
- httpApi: 'GET /users'
resources:
Resources:
userTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: ${self:custom.managedTablesDeletionPolicy.${self:provider.stage}, self:custom.managedTablesDeletionPolicy.default}
Properties:
TableName: ${self:provider.environment.USER_TABLE}
KeySchema:
- AttributeName: id
KeyType: HASH
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: GSI1_PK
AttributeType: S
- AttributeName: name
AttributeType: S
BillingMode: PAY_PER_REQUEST
GlobalSecondaryIndexes:
- IndexName: GSI1
KeySchema:
- AttributeName: GSI1_PK
KeyType: HASH
- AttributeName: name
KeyType: RANGE
Projection:
ProjectionType: ALL
Tags:
- Key: DDBTableGroupKey-${self:provider.stage}
Value: ${self:provider.stage}
- Key: OwnerService
Value: ${self:service}