Experiments with AWS step functions.
See setup and deployment instructions below.
See Workflow Lambda for code. Explanation in blog.
See Workflow Idempotent for code.
After deployment the API endpoints are listed as output like-
Outputs:
WorkflowIdempotentStack.WorkflowIdempotentApiEndpointXXXX = https://$api.execute-api.$region.amazonaws.com/prod/
Stack ARN:
arn:aws:cloudformation:region::stack/WorkflowIdempotentStack/id
Invoke using curl like
curl --request POST \
--url https://$api.execute-api.$region.amazonaws.com/prod/workflow \
--header 'Content-Type: application/json' \
--data '{
"name": "foo",
"input": { "data": "value"}
}'
the name is the id to be used for the workflow execution.
Workflow Stack implements the callback with token pattern. The flow diagram is shown below.
sequenceDiagram
participant client
participant systemGateway
participant systemLambda
participant systemStepfn
participant external
client->>+systemGateway: POST /tasks
systemGateway->>+systemLambda: invoke lambda for start
systemLambda->>systemStepfn: start workflow execution
activate systemStepfn
systemStepfn->>systemLambda: $workflow init
systemLambda->>-systemGateway: $taskId started
systemGateway->>-client: $taskId started
systemStepfn->>systemLambda: External service step
activate systemLambda
systemLambda->>+external: POST /external { id, resumeToken }
deactivate systemLambda
activate external
external->>+systemGateway: PUT /tasks/$taskId { id, resumeToken, status }
deactivate external
activate systemGateway
systemGateway->>+systemLambda: invoke lambda for update status
deactivate systemGateway
systemLambda->>systemStepfn: update workflow
systemStepfn->>systemLambda: $workflow update
systemLambda->>-systemGateway: $taskId updated
systemStepfn->>systemStepfn: workflow complete
deactivate systemStepfn
After deployment the API endpoints are listed as output like-
Outputs:
WorkflowsStack.ServiceApiEndpointXXXX = https://$api.execute-api.$region.amazonaws.com/prod/
WorkflowsStack.WorkflowApiEndpointYYYY = https://$apiComposite.execute-api.$region.amazonaws.com/prod/
Stack ARN:
arn:aws:cloudformation:region::stack/WorkflowsStack/id
Task | Endpoint sample |
---|---|
Start simple workflow | POST https://$api.execute-api.$region.amazonaws.com/prod/workflows |
Get simple workflow results | GET https://$api.execute-api.$region.amazonaws.com/prod/workflows/$workflowId |
Start composite workflow | POST https://$apiComposite.execute-api.$region.amazonaws.com/prod/compositeWorkflows |
Get composite workflow results | GET https://$apiComposite.execute-api.$region.amazonaws.com/prod/compositeWorkflows/$compositeWorkflowId |
This project is based on AWS CDK in typescript. Follow the steps in getting started for-
- aws account setup with credentials
- cdk cli installation (v2)
- cdk bootstrapping
Task | Command |
---|---|
install npm packages | npm install |
build | npm run build |
deploy to aws | cdk deploy -all |
destroy app | cdk destroy |