amazon-ecs-cli
amazon-ecs-cli copied to clipboard
Support scheduled tasks
I would like to manage the scheduled task with ecs-cli
.
For example:
-
ecs-cli scheduled create "command"
: Override with the specified command and schedule task with the latest task definition. -
ecs-cli scheduled list
: Display the scheduled task list. - When task definition is updated by
ecs-cli compose service up
, the task definition of the scheduled task is updated accordingly.
Is such a feature accepted?
@wata727 Yes, this is a valid request. We will look into this. Feel free to submit PRs to us if you already have something ready. Thanks!
We implemented our own standalone tool that creates/updates scheduled tasks, meant for CI pipelines:
ecs-schedule --cluster MYCLUSTER --region us-east-1 --task-definition ecs-schedule-example --schedule "cron(0 12 * * ? *)" --task-count 1
It doesn't support overriding container commands, env vars, or the task role but it wouldnt be that difficult to add at least command overrides similar to compose run
. It would be great to integrate this functionality under a ecs-cli schedule create
command. I can submit a PR for this feature request if desired!
Thanks for your great suggestion. At first, I thought that this feature was very useful, but now I do not think so... After all, because we want to manage the batch script with some kind of file, I noticed the merit of using ecs-cli schedule create
is small.
For this reason, this feature is no longer important to me. If there is no other request, please close it or lower the priority.
@rifelpet @wata727 I want this feature! I currently have 44 docker-compose.yml with tasks which are created automatically using the ecscli compose service up command. The services can be started simultaneously using a .sh script however I would like to create, delete and update scheduled tasks. @rifelpet If you have a tool you can share I would greatly appreciate it.
@yinshiua I'd like your opinion on implementing the CLI for this. Originally my idea was to take a task definition as a parameter to the command, but ecs-cli seems to mainly revolve around the use of compose files for creating tasks and services. Which would be more appropriate? If I use the compose-file parsing logic it may make more sense to create new subcommands under compose
, except compose
is meant to mimic docker-compose
commands which this would certainly deviate from.
Options I've come up with so far:
Make a new top level command that takes a task definition
(no other commands currently take a task def as a parameter)
ecs-cli schedule put --task-definition my-task-def:1 --schedule-expression "cron(0 * * * ? *)"
Make a new schedule
subcommand under compose that itself would have subsubcommands
This deviates compose
from "docker-compose-style commands" as the help docs indicate
ecs-cli compose -f docker-compose.yml schedule put --schedule-expression "cron(0 * * * ? *)"
Make a new top level command that takes a compose file just like the compose
command
ecs-cli schedule -f docker-compose.yml put --schedule-expression "cron(0 * * * ? *)"
For subcommands of schedule
i was thinking of put
, enable
, disable
, remove
to most closely match the CloudWatch API verbs. I like the idempotence that put
indicates, similar to compose's up
, but maybe create
would be more descriptive?
@rifelpet Ability to specify an alternate cluster name would be convenient if you want to have a separate cluster for scheduled tasks
@jspenc72 Yes it'll have the same --cluster and --region that every other command supports
@rifelpet For my use case, option #1 (new top level command that takes a task definition) would be ideal. Thanks for considering!
Any plans to complete this one? would be much nicer to wrap it up nicely and not require creation of the cloudwatch event/targets.
This would be ideal since there's no good way to do a lot of things with the CLI for scheduled tasks. Something as simple as altering the data in:
AWS Console -> EC2 Container Service -> Clusters -> cluster -> Scheduled Tasks -> schedule rule name Edit -> Target Name -> (field) Task definition
The CLI reference gives you access to everything except that field. I searched for ages looking for a way to change MyTaskDefinition:43 to MyTaskDefinition:44 when I make a change and there's just no great way through the base CLI to do this.
IMO, I think that it is better to use ecs-params.yml
recently added in #328 for this purpose now.
For example:
version: 1
task_definition:
ecs_network_mode: host
scheduled_tasks:
- schedule_expression: "cron(0 3 * * ? *)"
command: "bundle exec rake something"
container: "oneoff"
- schedule_expression: "cron(0 4 * * ? *)"
command: "awesome_command"
container: "oneoff"
This approach has the following advantages:
- You can manage cron tasks as a file on VCS.
- When
compose up
is executed, the scheduled tasks can be updated with latest task definition.- I always want to run cron tasks on the latest application.
How do you think about it?
P.S. By the way, I have already created elastic_whenever to solve this problem :)
Curious, has there been a cmd line update from AWS yet to solve this problem?
Is there any interest in deciding how to implement this in ecs-cli? More than happy to PR it if we can agree how it should look. I'm currently using ecs-cli for most of my ECS related tasks so it's a bit annoying to have to use another tool/scripts just for updating scheduled tasks which I imagine are integral to most peoples' ECS workflows.
Had similar issue. What I wanted to do was every time the CI pushes a new Container Image, the ones used by Scheduled Tasks should be updated. What I did is to create a new Task Definition that uses latest
tag (instead of normally git hash/branch tag) and specifically use it only for Scheduled Tasks.
Is there any update on this issue?
Agree, we need a CLI way to delete all scheduled tasks - I have 172 scheduled tasks that reference a specific environment variable (a replication database) and the only way to update to use a new replication database is to delete the tasks (one by one from console at the moment) and allow my Lambda to recreate them with a new environment variable. A cli command to either delete a specific scheduled task ( by UI) or delete all would be very helpful.