0

I have a EventBridge rule with the cron pattern cron(0/15 * ? * * *), which trigger an ECS task every 15 mins.

Is it possible to pass the trigger time to ECS task definition as a parameter? E.g., if the event is triggered on 2021-12-23T22:15:00Z.

[
  {
    ...
    "entryPoint": ["some_command", "--cron-time", "2021-12-23T22:15:00Z"],
    ...
  }
]

One solution in my mind is that I can create 672 (4 per hour * 24 hours * 7 days) of EventBridge rule/ECS task definition pairs, but it seems less than ideal.

Another solution will probably be a single rule that triggers a Lambda as a middle function to construct the parameter. However, I will prefer to have a no-code solution.

Thank you so much for your attention.

Mark B
  • 183,023
  • 24
  • 297
  • 295
EES
  • 1,584
  • 3
  • 20
  • 38
  • Why not just check the current time inside the ECS task as it starts up? If you absolutely need EventBridge to do this, then you can try using a Transform rule: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html If that doesn't work for you for some reason then using Lambda seems like the best option. – Mark B Dec 26 '21 at 15:01
  • @MarkB Some accuracy is required. ECS tasks can take some time to launch, and it is not guaranteed that the task will get triggered at the scheduled time (Personal experience due to service limit, for example). For my use case, the ECS task can run asynchronously, provided that the actual cron time is preserved and used as part of the application's query. I agree with you. Lambda seems the best bet here. – EES Dec 27 '21 at 16:47
  • @EES did you find a non-code solution to this? I'm looking for the same thing to pass the cron time as a string to a Glue Job. – Tim James Nov 04 '22 at 15:00
  • @Tim James Nope, ended up with a middle service to populate the closest trigger time and pass it to the downstream. – EES Nov 05 '22 at 23:55

1 Answers1

0

My solution would be using Step Functions (or Lambda) to store the time as a parameter in Systems Manager Parameter Store an run the task. Parameter could be included in the task definition as an environment variable (valueFrom) and container could read the time value form it.

Marko Eskola
  • 717
  • 4
  • 11