/
application_service.asl.json
166 lines (166 loc) · 4.97 KB
/
application_service.asl.json
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
{
"Comment": "This is a state machine for account application service",
"StartAt": "Verification",
"States": {
"Verification": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Check Identity",
"States": {
"Check Identity": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"InputPath": "$.data.identity",
"Parameters": {
"FunctionName": "${CheckIdentityFunctionArn}",
"Payload.$": "$"
},
"ResultSelector": {
"identity.$": "States.StringToJson($.Payload.body)"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 2,
"BackoffRate": 2
}
],
"End": true
}
}
},
{
"StartAt": "Check Address",
"States": {
"Check Address": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"InputPath": "$.data.address",
"Parameters": {
"FunctionName": "${CheckAddressFunctionArn}",
"Payload.$": "$"
},
"ResultSelector": {
"address.$": "States.StringToJson($.Payload.body)"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 2,
"BackoffRate": 2
}
],
"End": true
}
}
}
],
"ResultSelector": {
"identityResult.$": "$[0].identity",
"addressResult.$": "$[1].address"
},
"ResultPath": "$.results",
"Next": "Approve or Deny"
},
"Approve or Deny": {
"Type": "Choice",
"Choices": [
{
"And": [
{
"Variable": "$.results.identityResult.approved",
"BooleanEquals": true
},
{
"Variable": "$.results.addressResult.approved",
"BooleanEquals": true
}
],
"Next": "Add Account",
"Comment": "Application Approved"
}
],
"Default": "Deny Message"
},
"Add Account": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:putItem",
"InputPath": "$.data",
"Parameters": {
"TableName": "${AccountsTable}",
"Item": {
"email": {
"S.$": "$.identity.email"
},
"firstname": {
"S.$": "$.firstname"
},
"lastname": {
"S.$": "$.lastname"
},
"address": {
"S.$": "States.Format('{}, {}, {} - {}', $.address.street, $.address.city, $.address.state, $.address.zip)"
}
}
},
"ResultSelector": {
"statusCode.$": "$.SdkHttpMetadata.HttpStatusCode"
},
"ResultPath": "$.results.accountAddition",
"Next": "Home Insurance Interests"
},
"Home Insurance Interests": {
"Type": "Task",
"Resource": "arn:aws:states:::sqs:sendMessage",
"InputPath": "$..interests[?(@.category==home)]",
"Parameters": {
"QueueUrl": "${HomeInsuranceInterestQueueArn}",
"MessageBody.$": "$"
},
"ResultSelector": {
"statusCode.$": "$.SdkHttpMetadata.HttpStatusCode"
},
"ResultPath": "$.results.homeInsuranceInterests",
"Next": "Approved Message"
},
"Approved Message": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"TopicArn": "${SendCustomerNotificationSNSTopicArn}",
"Message.$": "States.Format('Hello {}, your application has been approved.', $.data.firstname)"
},
"ResultSelector": {
"statusCode.$": "$.SdkHttpMetadata.HttpStatusCode"
},
"ResultPath": "$.results.sendApprovedNotification",
"OutputPath": "$.results",
"End": true
},
"Deny Message": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"TopicArn": "${SendCustomerNotificationSNSTopicArn}",
"Message.$": "States.Format('Hello {}, your application has been denied because validation of provided data failed', $.data.firstname)"
},
"ResultSelector": {
"statusCode.$": "$.SdkHttpMetadata.HttpStatusCode"
},
"ResultPath": "$.results.sendDenyNotification",
"OutputPath": "$.results",
"End": true
}
}
}