-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
187 lines (174 loc) · 5.47 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
176
177
178
179
180
181
182
183
184
185
186
187
service: qldb-wallet-demo
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs14.x
memorySize: 512
stage: ${opt:stage, 'dev'}
region: ap-northeast-1
lambdaHashingVersion: "20201221"
tracing:
apiGateway: true
lambda: true # Optional, can be true (true equals 'Active'), 'Active' or 'PassThrough'
environment:
AWS_NODEJS_CONNECTION_REUSE_ENABLED : "1"
LEDGER_NAME: qldb-wallet-demo-${self:provider.stage}
LOG_LEVEL: WARN
POWERTOOLS_METRICS_NAMESPACE: ${self:service}
POWERTOOLS_LOGGER_SAMPLE_RATE: 0.2
iam:
role:
statements:
- Effect: Allow
Action:
- 'qldb:SendCommand'
Resource:
- !Sub "arn:aws:qldb:${AWS::Region}:${AWS::AccountId}:ledger/qldb-wallet-demo-${self:provider.stage}"
- Effect: Allow
Action:
- 'qldb:PartiQLInsert'
- 'qldb:PartiQLUpdate'
- 'qldb:PartiQLDelete'
- 'qldb:PartiQLSelect'
- 'qldb:PartiQLHistoryFunction'
Resource:
- !Sub "arn:aws:qldb:${AWS::Region}:${AWS::AccountId}:ledger/qldb-wallet-demo-${self:provider.stage}/*"
- Effect: "Allow"
Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Resource: "*" # Restrict resource to minimum required
plugins:
- serverless-iam-roles-per-function
- serverless-pseudo-parameters
- serverless-esbuild
functions:
createTable:
name: qldb-wallet-table-${self:provider.stage}
handler: functions/qldbTable.handler
iamRoleStatementsInherit: true
iamRoleStatementsName: qldb-wallet-demo-createTable
iamRoleStatements:
- Effect: Allow
Action:
- qldb:PartiQLCreateTable
Resource:
- "arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-wallet-demo-${self:provider.stage}/*"
memorySize: 256
timeout: 6
environment:
TABLE_NAME: DanielWallet
POWERTOOLS_SERVICE_NAME: createTable
createWallet:
name: create-wallet-${self:provider.stage}
handler: functions/createWallet.handler
environment:
POWERTOOLS_SERVICE_NAME: createWallet
iamRoleStatementsInherit: true
iamRoleStatementsName: qldb-wallet-demo-createWallet
iamRoleStatements:
- Effect: Allow
Action:
- qldb:PartiQLInsert
- qldb:PartiQLSelect
- qldb:PartiQLUpdate
Resource:
- "arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-wallet-demo-${self:provider.stage}/*"
events:
- httpApi:
path: /wallet
method: post
getBalance:
name: get-wallet-${self:provider.stage}
handler: functions/getBalance.handler
environment:
POWERTOOLS_SERVICE_NAME: getBalance
iamRoleStatementsInherit: true
iamRoleStatementsName: qldb-wallet-demo-getBalance
iamRoleStatements:
- Effect: Allow
Action:
- qldb:PartiQLSelect
Resource:
- "arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-wallet-demo-${self:provider.stage}/*"
events:
- http:
path: /wallet/{guid}
method: get
addFunds:
name: add-balance-${self:provider.stage}
handler: functions/addFunds.handler
environment:
POWERTOOLS_SERVICE_NAME: updateWallet
iamRoleStatementsInherit: true
iamRoleStatementsName: qldb-wallet-demo-updateWallet
iamRoleStatements:
- Effect: Allow
Action:
- qldb:PartiQLSelect
- qldb:PartiQLUpdate
Resource:
- "arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-wallet-demo-${self:provider.stage}/*"
events:
- http:
path: /wallet/deposit/{guid}
method: put
withdrawFunds:
name: withdraw-balance-${self:provider.stage}
handler: functions/withdrawFunds.handler
environment:
POWERTOOLS_SERVICE_NAME: updateWallet
iamRoleStatementsInherit: true
iamRoleStatementsName: qldb-wallet-demo-withdrawWallet
iamRoleStatements:
- Effect: Allow
Action:
- qldb:PartiQLSelect
- qldb:PartiQLUpdate
Resource:
- "arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-wallet-demo-${self:provider.stage}/*"
events:
- http:
path: /wallet/withdraw/{guid}
method: put
deleteWallet:
name: delete-balance-${self:provider.stage}
handler: functions/deleteWallet.handler
environment:
POWERTOOLS_SERVICE_NAME: deleteWallet
iamRoleStatementsInherit: true
iamRoleStatementsName: qldb-wallet-demo-deleteWallet
iamRoleStatements:
- Effect: Allow
Action:
- qldb:PartiQLSelect
- qldb:PartiQLDelete
Resource:
- "arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-wallet-demo-${self:provider.stage}/*"
events:
- http:
path: /wallet/{guid}
method: delete
resources:
Resources:
qldbLedger:
Type: AWS::QLDB::Ledger
Properties:
Name: qldb-wallet-demo-${self:provider.stage}
DeletionProtection: false
PermissionsMode: STANDARD
Tags:
- Key: name
Value: qldb-wallet-demo
qldbTable:
Type: Custom::qldbTable
DependsOn: qldbLedger
Properties:
ServiceToken: !GetAtt CreateTableLambdaFunction.Arn
Version: 1.0 #change this to force redeploy
Outputs:
qldbBicycleWalletLedger:
Value:
Ref: qldbLedger
Export:
Name: qldb-wallet-demo