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

2

1

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 :)

Electroballistics answered 7/6, 2021 at 20:40 Comment(2)
Yeah, if I replace it with "TimestampEquals": "2016-03-14T01:59:00Z", it works. The string must conform with the RFC3339 profile of ISO 8601. Not taking any other format!Powerhouse
I know that it works with static strings, but I can't have "magic strings" in this case.. I have to compare a variable to another variable.Electroballistics
E
2

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!

Electroballistics answered 9/6, 2021 at 12:4 Comment(1)
And in Workflow Studio, note that you must select Timestamp Variable not Timestamp Constant (same with Number Variable/Timestamp)Ashwell
L
0

Looks like you indeed found a way around your initial challenge from the thread linked below.

Using an amazon step function, how do I write a choice operator that references current time?

However, I thought you wanted to compare $.staleInputVariable to the current timestamp and I wince to think you had to configure a lambda function (and test it!) to do only that.

If so, you could have achieved that simply by using the Context Object or $$.:

{
  "Variable": "$$.State.EnteredTime",
  "TimestampEqualsPath": "$.staleInputVariable"
}
Lamellar answered 13/2, 2022 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.