Pagination loop

Use Amazon States language (ASL) to implement a for-loop without writing code

This pattern shows how to use Amazon States language (ASL) to implement a for-loop without writing code. The workflow uses the `ListExecutions` SDK call, to retrive all previous Workflow executions.
The maximum number of executions that can be returned for each call is 100. If the workflow execution history shows more than 100, then a pagination token is returned, This can then be used to access the next 100 executions, and so on.
When no Pagination token is returned, the loop is complete.
Extend this pattern for any type of loop by using a `Choice` state with a default rule to check for more items, and an exit path if no more items are found.

Launch Stack
< Back to all workflows

GitHub icon View this workflow on GitHub


Clone repo

git clone https://github.com/aws-samples//step-functions-workflows-collection/tree/main/pagination-loop/cd step-functions-workflows-collection/pagination-loop/

Deploy

sam deploy --guided


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

1. Delete the stack: sam delete --stack-name STACK_NAME.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Additional resources

Created by:

Benjamin Smith

Benjamin Smith

Ben is a senior developer advocate for Serverless Applications at Amazon Web Services based in London, UK. Prior to joining AWS Ben worked in a number of different technical roles specializing in workflow Automation and web development.

Follow on LinkedIn