Home > Software engineering >  Choice - Compare value in input to empty string
Choice - Compare value in input to empty string

Time:04-20

Using AWS Step Functions with a Choice state, how can one check if a value in the input is equal to an empty string?

  • IsPresent may be used to check if a particular key exists in the input, but it will return true for an empty string.
  • StringEquals may be used to compare a string key against a non-empty value
  • StringMatches may be used to compare a string key against a non-empty wildcard (*) pattern

Setting StringEmpty's or StringMatches's comparison value to empty is invalid in the Workflow Studio UI.

Update

This is a bug/issue in the current version of the AWS Console Workflow Studio. Comparing to empty is valid, but the UI disallows this configuration via client-side validation.

CodePudding user response:

The StringEquals condition matches an empty string as you would expect.

"EmptyString?": {
    "Type": "Choice",
    "Choices": [
      {
        "Variable": "$.TestField",
        "StringEquals": "",
        "Next": "EmptyString"
      }
    ],
    "Default": "NotEmptyString"
  },

An empty string in the input matches the StringEquals "" choice:

{
    "TestField": ""
}
  • Related