- Newest
- Most votes
- Most comments
To achieve your goal of processing 20 targets with different flows for successful and failed API calls using AWS Step Functions, you can use a Map state with a nested workflow that includes error handling.
Here's how you can implement this:
- Create a Map state that iterates over your 20 targets.
- Within the Map state, define a workflow that:
- Makes the API call to each target
- Uses error handling to direct the flow based on success or failure
The Map state will process each target in your array, and you can use error handling within each iteration to direct the flow. For successful API calls, the execution will follow your "success" path, while failed calls can be caught and directed to your "failure" path.
You can implement this using the Inline Map state, which runs each iteration in the context of the parent workflow. The Inline Map state accepts a JSON array as input and can process up to 40 concurrent iterations, which is sufficient for your 20 targets.
In your Map state configuration:
- Use the ItemProcessor field to define the workflow steps for each target
- Include error handling within the workflow to catch failures
- Use the StartAt field to specify the first state in your workflow
- Define the States object to include your API call and subsequent branching logic
If your workflow is more complex or requires higher concurrency, you might consider using the Distributed Map state instead, which can handle up to 10,000 parallel executions.
Remember that in Inline mode, the failure of any iteration causes the entire Map state to fail unless you implement proper error handling within your workflow.
Sources
Map workflow state - AWS Step Functions
Using Map state in Inline mode in Step Functions workflows - AWS Step Functions
Learn about state machines in Step Functions - AWS Step Functions
Discovering workflow states to use in Step Functions - AWS Step Functions
answered a year ago
You can achieve what you are after by using error handling within each Map iteration. You catch the error, mark the iteration as failed and continue with next targets. You do the same with successful executions. Once the map is over, you have two states that run in parallel, one processing successes and the other failures. It could be something similar to this:
{ "StartAt": "ProcessAPIConfigurations", "States": { "ProcessAPIConfigurations": { "Type": "Map", "ItemsPath": "$.configurations", "ItemProcessor": { "StartAt": "CallAPI", "States": { "CallAPI": { "Type": "Task", "Resource": "arn:aws:states:::http:invoke", "Parameters": { "ApiEndpoint.$": "$.endpoint", "Method": "POST", "RequestBody.$": "$.payload" }, "Catch": [ { "ErrorEquals": ["States.ALL"], "Next": "MarkAsFailed" } ], "Next": "MarkAsSuccess" }, "MarkAsSuccess": { "Type": "Pass", "Parameters": { "status": "SUCCESS", "data.$": "$" }, "End": true }, "MarkAsFailed": { "Type": "Pass", "Parameters": { "status": "FAILED", "data.$": "$" }, "End": true } } }, "Next": "ProcessResults" }, "ProcessResults": { "Type": "Parallel", "Branches": [ { "StartAt": "HandleSuccesses", "States": { "HandleSuccesses": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": { "FunctionName": "handle-successes", "Payload": { "items.$": "$[?(@.status == 'SUCCESS')]" } }, "End": true } } }, { "StartAt": "HandleFailures", "States": { "HandleFailures": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Parameters": { "FunctionName": "handle-failures", "Payload": { "items.$": "$[?(@.status == 'FAILED')]" } }, "End": true } } } ], "End": true } } }
answered a year ago
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 3 years ago
