How to: Clean the Contents of AWS Step Function Path Variables

AWS Step Functions provides serverless flow orchestration capability.

Problem

Normally you would execute a flow orchestration once per transaction, but sometimes you need to iterate through many transactions in a loop as part of your orchestration. In this case where you iterate in sequence (and not in parallel) you sometimes need to ensure the path variables aren’t re-used i.e. are ‘clean’ between iterations.

This happened to me recently when the target system I was working with could only handle one transaction at a time, not a typical scenario in an enterprise IT environment.

Solution

Set a “pass” type task in the step function flow, and add the path variables you want to keep under “parameters” section as follows:


"CleanVars": {
              "Type": "Pass",
              "InputPath": "$",
              "Parameters": {
                "FileName.$": "$.FileName",
                "BucketName.$": "$.BucketName",
                "data.$": "$.data",
                "iterator.$": "$.iterator"
              },
              "ResultPath": "$",
              "Next": "NextTask"
            },