Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StepFunction's Choice rule to check if array field is empty

Is there a way to create a Choice rule in StepFunction to determine if an array field has any elements?

Current StepFunction documentation doesn't list any collection-specific comparison operators so I'm wondering if it's possible to achieve this without implementing a separate lambda to test if an array is empty?

like image 801
Yuriy Bondaruk Avatar asked Jan 11 '19 14:01

Yuriy Bondaruk


3 Answers

Adding to @cclusetti 's answer, you can use IsPresent to check whether the first element of your array exists. If it is present, the array is not empty. If it is not present, then either the array is empty or missing.

"Choices":[
   {
     "Variable":"$.myArray[0]",
     "IsPresent":true,
     "Next":"NotEmpty"
   }
]
like image 63
subten Avatar answered Oct 20 '22 04:10

subten


No, you cannot check array field in Choice state. Only way is to set it in the input received from the preceding state.

"Choices":[
   {
     "Variable":"$.isEmpty",
     "BooleanEquals":true,
     "Next":"NextState"
   }
]
like image 40
A.Khan Avatar answered Oct 20 '22 02:10

A.Khan


As of Aug 2020, post release, aws has added isPresent and to Choice states. An option here is that if your array is empty then either don't set the key or set it to null

like image 1
cclusetti Avatar answered Oct 20 '22 02:10

cclusetti