Search code examples
amazon-web-servicestimestampmatching

AWS Step function - choice step - TimestampEquals matching with multiple input variables


I have been trying to create a step function with a choice step that acts as a rule engine. I would like to compare a date variable (from the stale input JSON) to another date variable that I generate with a lambda function.

AWS documentation does not go into details about the Timestamp comparator functions, but I assumed that it can handle two input variables. Here is the relevant part of the code:

{
  "Variable": "$.staleInputVariable",
  "TimestampEquals": "$.generatedTimestampUsingLambda"
}

Here is the error that I am getting when trying to update(!!!) the stepFunction. I would like to highlight the fact that I don't even get to invoking the stepFunction as it fails while updating the function.

Resource handler returned message: "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: String does not match RFC3339 timestamp at ..... (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: 97df9775-7d2d-4dd2-929b-470c8s741eaf; Proxy: null)" (RequestToken: 030aa97d-35a5-a6a5-0ac5-5698a8662bc2, HandlerErrorCode: InvalidRequest)

The stepfunction updates without the Timestamp matching, therefore, I suspect this bit of code.. Any guess?

EDIT (08.Jun.2021):

A comparison – Two fields that specify an input variable to compare, the type of comparison, and the value to compare the variable to. Choice Rules support comparison between two variables. Within a Choice Rule, the value of Variable can be compared with another value from the state input by appending Path to name of supported comparison operators. Source: AWS docs

It clearly states that two variables can be compared, but to no avail. Still trying :)


Solution

  • When I explained the problem to one of my peers, I realised that the AWS documentation mentions a Path postfix (which I confused with the $.). This Path needs to be added to the operatorName.

    The following code works:

    {
      "Variable": "$.staleInputVariable",
      "TimestampEqualsPath": "$.generatedTimestampUsingLambda"
    }
    

    Again, I would like to draw your attention to the "Path" word. That makes the magic!