-
Notifications
You must be signed in to change notification settings - Fork 3
/
serverless.yml
111 lines (105 loc) · 2.98 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
service: sls-sm-21
plugins:
- serverless-step-functions
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs14.x
lambdaHashingVersion: 20201221
stage: dev
region: eu-central-1
environment:
BITCOIN_LEDGER: { "Ref": "BitcoinLedger" }
PENDING_TRANSACTIONS_TABLE: { "Ref": "PendingTransactionsTable" }
iamRoleStatements:
- Effect: Allow
Action:
- states:SendTaskSuccess
- states:StartExecution
Resource: "*" # Because of circular dependencies
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:GetItem
- dynamodb:DeleteItem
Resource: { "Fn::GetAtt": ["PendingTransactionsTable", "Arn"] }
- Effect: Allow
Action:
- dynamodb:Scan
- dynamodb:DeleteItem
Resource: { "Fn::GetAtt": ["BitcoinLedger", "Arn"] }
functions:
pullLedgerData:
handler: src/pullLedgerData.handler
events:
- schedule: rate(5 minutes)
createOrder:
handler: src/createOrder.handler
environment:
PROCESS_ORDER_SM: { "Ref": "ProcessOrderStepFunctionsStateMachine" }
events:
- http:
path: order
method: PUT
generateAddress:
handler: src/generateAddress.handler
waitForBlocks:
handler: src/waitForBlocks.handler
shipOrder:
handler: src/shipOrder.handler
stepFunctions:
validate: true
stateMachines:
processOrder:
definition:
StartAt: Generate Bitcoin address QR code
States:
Generate Bitcoin address QR code:
Type: Task
Resource: arn:aws:states:::lambda:invoke
OutputPath: "$.Payload"
Parameters:
FunctionName: { "Ref": "generateAddress" }
Payload.$: "$"
Next: Wait for 10 block confirmations
Wait for 10 block confirmations:
Type: Task
Resource: arn:aws:states:::lambda:invoke.waitForTaskToken
Parameters:
FunctionName: { "Ref": "waitForBlocks" }
Payload:
input.$: "$"
taskToken.$: "$$.Task.Token"
Next: Ship customer's order
Ship customer's order:
Type: Task
Resource: arn:aws:states:::lambda:invoke
OutputPath: "$.Payload"
Parameters:
FunctionName: { "Ref": "shipOrder" }
Payload.$: "$"
End: true
resources:
Resources:
BitcoinLedger:
Type: AWS::DynamoDB::Table
Properties:
TableName: bitcoin-ledger
AttributeDefinitions:
- AttributeName: blockHash
AttributeType: S
KeySchema:
- AttributeName: blockHash
KeyType: HASH
BillingMode: PAY_PER_REQUEST
PendingTransactionsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: pending-transactions
AttributeDefinitions:
- AttributeName: address
AttributeType: S
KeySchema:
- AttributeName: address
KeyType: HASH
BillingMode: PAY_PER_REQUEST