Home > Mobile >  Parameterise AWS EventBridge cron rules with ECS task
Parameterise AWS EventBridge cron rules with ECS task

Time:12-27

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.

CodePudding user response:

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.

CodePudding user response:

Can you please share the task defination. And command use to start container. We can modify your docker cmd command which includes the actual command plus the command which set current date time as env

  • Related