1

I have a Event Bridge trigger, which triggers the stepfunction. I have below input json for stepfunction. How would I send the execution_date as current_date in yyyy-mm-dd format.

{
   "id": "1",
   "execution_date": "2023-06-07"
}

Im using terraform for creating the event bridge. Here is the resource of terraform. Has someone faced this situation? is it possible to create dynamic input json to trigger the stepfunction from event bridge?

  • Can you say more about how you would like this to be dynamic? I'm assuming from what you wrote above that you are starting from using Input (static JSON data). Will you have an event payload from the Rule that triggers this and you want to extract data from it? Or are you just running this on a schedule? – Justin Callison Jun 07 '23 at 12:51
  • Dynamic, here I meant, current_date as execution_date, which would be changing everyday. It is just running on a schedule :) – OnTheWheels Jun 08 '23 at 13:02

1 Answers1

2

You have a few options here.

It seems you are using EventBridge Scheduled Rules. With these, you can use an InputTransformer on your Target and the predefined variable for <aws.events.event.ingestion-time>.

You could also move to the recently released EventBridge Scheduler, where you can use the <aws.scheduler.scheduled-time> context attribute.

And lastly, you could do this inside your Step Functions workflow, using the Context Object as in the example below.

{
  "StartAt": "Add Execution Context",
  "States": {
    "Add Execution Context": {
      "Type": "Pass",
      "End": true,
      "ResultPath": "$.execution_context",
      "Parameters": {
        "execution_date.$": "States.ArrayGetItem(States.StringSplit($$.Execution.StartTime,'T'), 0)"
      }
    }
  }
}

This will augment your input payload with that data. So if you passed this into the state machine defined above:

{
  "id": "25"
}

You'd get:

{
  "id": "25",
  "execution_context": {
    "execution_date": "2023-06-08"
  }
}
Justin Callison
  • 1,279
  • 2
  • 6