Search code examples
amazon-web-servicesaws-step-functions

AWS Step Function how to imitate StringStartsWith condition?


I need to invoke different lambda depends on first letter of payload field. There is no appropriate Choice Rule. Is there any workaround ?


Solution

  • If you're matching on the value of the field, it's possible to use the StringMatches operator.

    For instance, this should check $.some_field value and move to state Goto_A,Goto_B,Goto_C or if none match Goto_Error.

    States:
      Choice_FirstLetterOfSomeField:
        Type: Choice
        Choices:
          - Variable: $.some_field
            StringMatches: 'a*'
            Next: Goto_A
          - Variable: $.some_field
            StringMatches: 'b*'
            Next: Goto_B
          - Variable: $.some_field
            StringMatches: 'c*'
            Next: Goto_C
        Default: Goto_Error