Skip to content

Instantly share code, notes, and snippets.

@half2me
Created September 14, 2022 10:27
Show Gist options
  • Save half2me/9da73ccc7a1be410e7c8ca843ee9b856 to your computer and use it in GitHub Desktop.
Save half2me/9da73ccc7a1be410e7c8ca843ee9b856 to your computer and use it in GitHub Desktop.
DynamoDB table iteration with a StepFunction
{
"StartAt": "Add empty LastEvaluatedKey",
"States": {
"Add empty LastEvaluatedKey": {
"Type": "Pass",
"Next": "Scan",
"Result": {
"LastEvaluatedKey": null
},
"ResultPath": "$"
},
"Scan": {
"Type": "Task",
"Next": "Map",
"Parameters": {
"TableName": "",
"ProjectionExpression": "#id",
"ExpressionAttributeNames": {
"#id": "id"
},
"ExclusiveStartKey.$": "$.LastEvaluatedKey"
},
"Resource": "arn:aws:states:::aws-sdk:dynamodb:scan"
},
"Map": {
"Type": "Map",
"Next": "Check for more",
"Iterator": {
"StartAt": "Process",
"States": {
"Process": {
"Type": "Pass",
"End": true
}
}
},
"ItemsPath": "$.Items",
"ResultPath": null,
"MaxConcurrency": 40
},
"Check for more": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.LastEvaluatedKey",
"IsPresent": true,
"Next": "Add new LastEvaluatedKey"
}
],
"Default": "Done"
},
"Done": {
"Type": "Succeed"
},
"Add new LastEvaluatedKey": {
"Type": "Pass",
"Next": "Scan",
"Parameters": {
"LastEvaluatedKey.$": "$.LastEvaluatedKey"
},
"ResultPath": null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment