Created
March 16, 2022 05:30
-
-
Save sam-goodwin/35e2ba431602be27f3c68345d5162971 to your computer and use it in GitHub Desktop.
Step Function TS to ASL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
StartAt: "State1", | |
States: { | |
State1: { | |
Catch: [ | |
{ | |
ErrorEquals: ["States.All"], | |
Next: "Throw", | |
}, | |
], | |
Next: "State2", | |
ResultPath: "$.person", | |
Parameters: { | |
Key: { | |
id: { | |
"S.$": "$.id", | |
}, | |
}, | |
TableName: personTable.resource.tableName, | |
}, | |
Resource: "arn:aws:states:::aws-sdk:dynamodb:getItem", | |
Type: "Task", | |
}, | |
State2: { | |
Choices: [ | |
{ | |
Or: [ | |
{ | |
Variable: "$.person.Item", | |
IsPresent: false, | |
}, | |
{ | |
Variable: "$.person.Item", | |
IsNull: true, | |
}, | |
], | |
Next: "State3", | |
}, | |
], | |
Default: "State4", | |
Type: "Choice", | |
}, | |
State3: { | |
Next: "Success", | |
Parameters: { | |
result: null, | |
}, | |
OutputPath: "$.result", | |
Type: "Pass", | |
}, | |
State4: { | |
Catch: [ | |
{ | |
ErrorEquals: ["States.All"], | |
Next: "Throw", | |
}, | |
], | |
Next: "State5", | |
ResultPath: "$.score", | |
Parameters: { | |
person: { | |
"id.$": "$.person.Item.id.S", | |
"name.$": "$.person.Item.name.S", | |
}, | |
}, | |
Resource: computeScore.resource.functionArn, | |
Type: "Task", | |
}, | |
State5: { | |
Next: "Success", | |
Parameters: { | |
result: { | |
"id.$": "$.person.Item.id.S", | |
"name.$": "$.person.Item.name.S", | |
"score.$": "$.score", | |
}, | |
}, | |
OutputPath: "$.result", | |
Type: "Pass", | |
}, | |
Success: { | |
Type: "Succeed", | |
}, | |
Throw: { | |
Error: "TODO", | |
Type: "Fail", | |
}, | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new ExpressStepFunction( | |
stack, | |
"fn", | |
(id: string): (Person & { score: number }) | undefined => { | |
const person = $AWS.DynamoDB.GetItem({ | |
TableName: personTable, | |
Key: { | |
id: { | |
S: id, | |
}, | |
}, | |
}); | |
if (person.Item === undefined) { | |
return undefined; | |
} | |
const score = computeScore({ | |
id: person.Item.id.S, | |
name: person.Item.name.S, | |
}); | |
return { | |
id: person.Item.id.S, | |
name: person.Item.name.S, | |
score, | |
}; | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment