|
| 1 | +# Use EventBridge Scheduler to Trigger Scheduled Fargate Tasks |
| 2 | + |
| 3 | +* Status: accepted |
| 4 | +* Deciders: |
| 5 | + * Jamie Visker |
| 6 | + * Josh Gubler |
| 7 | + * Scott Hutchings |
| 8 | + * Spencer Visker |
| 9 | +* Date: 2023-09-26 |
| 10 | + |
| 11 | +## Context and Problem Statement |
| 12 | + |
| 13 | +We used CloudWatch Event Rules and Targets to trigger scheduled Fargate tasks. |
| 14 | +AWS has a newer service called [EventBridge Scheduler](https://docs.aws.amazon.com/eventbridge/latest/userguide/scheduler.html). |
| 15 | +Do we start using the Scheduler to take advantage of those newer features? |
| 16 | + |
| 17 | +## Decision Drivers <!-- optional --> |
| 18 | + |
| 19 | +* Would be nice if our tasks could support time zone scheduled jobs |
| 20 | +* Needs to be easy to use |
| 21 | + |
| 22 | +## Considered Options |
| 23 | + |
| 24 | +* Keep using Event Rules and Targets |
| 25 | +* Use EventBridge Scheduler (keep event trigger functionality) |
| 26 | +* Use EventBridge Scheduler (move event trigger functionality to new module) |
| 27 | +* Use EventBridge Scheduler and refactor fargate modules |
| 28 | + |
| 29 | +## Decision Outcome |
| 30 | + |
| 31 | +Chosen option: "Use EventBridge Scheduler (keep event trigger functionality)", because it'll give us the best of both worlds with using the new Scheduler and still supporting events. |
| 32 | + |
| 33 | +### Positive Consequences <!-- optional --> |
| 34 | + |
| 35 | +* We were able to implement in such a way that a fargate task can be both scheduled and triggered by an event with the same module. |
| 36 | + |
| 37 | +### Negative Consequences <!-- optional --> |
| 38 | + |
| 39 | +* Using the Scheduler removes the fargate task from the "Scheduled tasks" portion of the ECS cluster on the AWS console. |
| 40 | + |
| 41 | +## Pros and Cons of the Options <!-- optional --> |
| 42 | + |
| 43 | +### Keep using Event Rules and Targets |
| 44 | + |
| 45 | +* Good, because there'll be no change to our module |
| 46 | +* Good, because it still works |
| 47 | +* Bad, because we can't take advantage of the EventBridge Scheduler features (time zone, start-end dates, retries etc.) |
| 48 | + |
| 49 | +### Use EventBridge Scheduler (keep event trigger functionality) |
| 50 | + |
| 51 | +* Good, because we can take advantage of the EventBridge Scheduler features (time zone, start-end dates, retries etc.) |
| 52 | +* Good, because we can still support tasks triggered by tasks |
| 53 | +* Bad, because the module will be more complex (it will include resources for both EventBridge Scheduler, and CloudWatch Rules and Targets) |
| 54 | +* Bad, because using the Scheduler removes the task from the list of "Scheduled Tasks" in the ECS cluster |
| 55 | + |
| 56 | +### Use EventBridge Scheduler (move event trigger functionality to new module) |
| 57 | + |
| 58 | +* Good, because we can take advantage of the EventBridge Scheduler features (time zone, start-end dates, retries etc.) |
| 59 | +* Good, because this module will be simplified |
| 60 | +* Bad, because in order to support tasks triggered by tasks we'll need to create a new module (with lots of copy/paste terraform configuration) |
| 61 | +* Bad, because using the Scheduler removes the task from the list of "Scheduled Tasks" in the ECS cluster |
| 62 | + |
| 63 | +### Use EventBridge Scheduler and refactor fargate modules |
| 64 | + |
| 65 | +We can refactor the fargate-api, and scheduled-fargate modules into smaller pieces that work together in order to reduce duplicate terraform code. |
| 66 | +Maybe something like: |
| 67 | +* `fargate-definition` module that sets up the fargate task definition, ECS cluster, SGs, related IAM roles etc. |
| 68 | +* `fargate-service` module that takes task definition and cluster inputs from 'fargate-defintion' module, and creates an ECS service with ALB, CodeDeploy, related IAM roles etc. |
| 69 | +* `fargate-scheduled` module that takes task definition and cluster inputs from 'fargate-defintion' module, and creates Scheduler that runs the task on the schedule, related IAM roles etc. |
| 70 | +* `fargate-event` module that takes task definition and cluster inputs from 'fargate-defintion' module, and creates CloudWatch Event to trigger task, Rule(s), Target(s), and related IAM roles etc. |
| 71 | + |
| 72 | +* Good, because we can reduce duplicate terraform |
| 73 | +* Good, because our modules can be smaller and simpler, thus easier to maintain |
| 74 | +* Bad, because it completely breaks our exising terraform module contract, so upgrades will be more difficult |
| 75 | +* Bad, because it makes our apps a little more complex having to use interconnected modules instead of just one. It borders on not needing modules in the first place if our apps have to know how everything integrates. |
| 76 | +* Bad, because using the Scheduler removes the task from the list of "Scheduled Tasks" in the ECS cluster |
| 77 | + |
| 78 | +## Links <!-- optional --> |
| 79 | + |
| 80 | +* [EventBridge Scheduler](https://docs.aws.amazon.com/eventbridge/latest/userguide/scheduler.html) |
0 commit comments