Setting the file. One moment. Semaphore Concurrency Lock Asl · AWS Step Functions · aws/agent-toolkit-for-aws · Skills Docs70
Creating Amazon Aurora Db Cluster With Instances
93
Routing Traffic With Route53 And CloudFront
Resilience Program Design
116.4
Migrating From Jsonpath To Jsonata
assets/semaphore-concurrency-lock.asl.json
JSON·131 lines·3 KB
: {
11 "lockId": {
12 "S": "{% $states.input.customerId %}"
13 },
14 "executionId": {
15 "S": "{% $states.context.Execution.Id %}"
16 },
17 "expiresAt": {
18 "N": "{% $string($toMillis($now()) + 900000) %}"
19 }
20 },
21 "ConditionExpression": "attribute_not_exists(lockId) OR expiresAt < :now",
22 "ExpressionAttributeValues": {
23 ":now": {
24 "N": "{% $string($toMillis($now())) %}"
25 }
26 }
27 },
28 "Assign": {
29 "customerId": "{% $states.input.customerId %}"
30 },
31 "Output": "{% $states.input %}",
32 "Retry": [
33 {
34 "ErrorEquals": [
35 "DynamoDB.ConditionalCheckFailedException"
36 ],
37 "IntervalSeconds": 5,
38 "MaxAttempts": 12,
39 "BackoffRate": 1.5,
40 "JitterStrategy": "FULL"
41 }
42 ],
43 "Catch": [
44 {
45 "ErrorEquals": [
46 "DynamoDB.ConditionalCheckFailedException"
47 ],
48 "Assign": {
49 "customerId": "{% $states.input.customerId %}",
50 "lockError": "{% $states.errorOutput %}"
51 },
52 "Next": "LockUnavailable"
53 }
54 ],
55 "Next": "DoProtectedWork"
56 },
57 "DoProtectedWork": {
58 "Type": "Task",
59 "Resource": "arn:aws:states:::lambda:invoke",
60 "Arguments": {
61 "FunctionName": "arn:aws:lambda:us-east-1:123456789012:function:ProcessCustomer:$LATEST",
62 "Payload": "{% $states.input %}"
63 },
64 "Output": "{% $states.result.Payload %}",
65 "Catch": [
66 {
67 "ErrorEquals": [
68 "States.ALL"
69 ],
70 "Assign": {
71 "workError": "{% $states.errorOutput %}"
72 },
73 "Next": "ReleaseLock"
74 }
75 ],
76 "Next": "ReleaseLock"
77 },
78 "ReleaseLock": {
79 "Type": "Task",
80 "Resource": "arn:aws:states:::dynamodb:deleteItem",
81 "Arguments": {
82 "TableName": "LocksTable",
83 "Key": {
84 "lockId": {
85 "S": "{% $customerId %}"
86 }
87 },
88 "ConditionExpression": "executionId = :execId",
89 "ExpressionAttributeValues": {
90 ":execId": {
91 "S": "{% $states.context.Execution.Id %}"
92 }
93 }
94 },
95 "Retry": [
96 {
97 "ErrorEquals": [
98 "States.ALL"
99 ],
100 "IntervalSeconds": 1,
101 "MaxAttempts": 3,
102 "BackoffRate": 2.0
103 }
104 ],
105 "Next": "CheckWorkResult"
106 },
107 "CheckWorkResult": {
108 "Type": "Choice",
109 "Choices": [
110 {
111 "Condition": "{% $exists($workError) %}",
112 "Next": "WorkFailed"
113 }
114 ],
115 "Default": "Done"
116 },
117 "WorkFailed": {
118 "Type": "Fail",
119 "Error": "{% $exists($workError.Error) ? $workError.Error : 'WorkFailed' %}",
120 "Cause": "{% $exists($workError.Cause) ? $workError.Cause : 'Protected work failed' %}"
121 },
122 "Done": {
123 "Type": "Succeed"
124 },
125 "LockUnavailable": {
126 "Type": "Fail",
127 "Error": "LockContention",
128 "Cause": "{% 'Could not acquire lock for ' & $customerId & ' after retries' %}"
129 }
130 }
131}