Search code examples
aws-step-functions

Use Integers instead of Strings when creating a Task in Step Functions


How can I create a task with Integer input types as opposed to String, for example say I want to kick off a state machine:

        "SomeStage": {
              "Comment": "Getting busy with Foo Bar",
              "Type": "Task",
              "Resource": "arn:aws:states:::states:startExecution.waitForTaskToken",
              "Parameters": {
                "StateMachineArn": "arn:aws:states:ap-southeast-2:1234567:stateMachine:mrFooBar",
                "Input": {
                  "foo.$": "$.foo",
                  "bar.$": "$.bar",
                }
              },
      ...
      "End": true
    }

My parameters: $.foo & $.bar, turn out to be inputs as Strings in the mrFooBar statemachine. If I remove the quotes I get a compile error. This issue is very annoying I can't figure out how to get rid of the quotes so that my parameters will be integers in the state machine it kicks off.


Solution

  • The StringToJson intrinsic function will convert a string input to a number:

    "Input": {
        "foo.$": "States.StringToJson($.foo)",
        "bar.$": "States.StringToJson($.bar)"
    }