Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Question: Running one-off tasks #24

Open
shinzui opened this issue Jun 23, 2016 · 5 comments
Open

Question: Running one-off tasks #24

shinzui opened this issue Jun 23, 2016 · 5 comments

Comments

@shinzui
Copy link

shinzui commented Jun 23, 2016

How do you run one-off tasks, such as running a script or a database migration against a container/task definition?

I currently have a very similar terraform setup but I run one-off tasks through the aws cli.

@achille-roussel
Copy link
Contributor

Do you mean something that is repeated daily or just ad-hoc operations?

Cron jobs work well for the former, you could bake it into the AMI. Depending on your use case you can also have a "worker" in the form of an ECS task that just sleeps and runs at regular intervals or a "service" that executes your commands.

It's hard to tell what would be the best approach as this seems very use-case specific to me, if you wanna share more about what your needs are maybe we can come up with something interesting that could be added to stack.

@shinzui
Copy link
Author

shinzui commented Jun 23, 2016

I was asking about ad-hoc operations such as running a script to fix some data, or running database migrations.... Currently, I duplicate my service task definition in terraform and omit the port mappings, then run aws ecs run-task against it with a command override to run a specific command.

@gregwebs
Copy link
Contributor

gregwebs commented Sep 9, 2016

That's a good solution I want to start using: seems like you just need to automate it (use terraform outputs plus the aws cli). I sometimes end up doing ssh + docker run/exec

@shinzui
Copy link
Author

shinzui commented Sep 9, 2016

I use terraform's null_resource to generate the required ecs task cli input.

resource "null_resource" "batch_task_cli_input" {
  triggers {
    variables = "${data.template_file.batch_task_cli_input.rendered}"
  }

  provisioner "local-exec" {
    command = "echo '${data.template_file.batch_task_cli_input.rendered}' > ../../tmp/ecs-task-cli-input.json"
  }
}

@gregwebs
Copy link
Contributor

I created a script for this. You will need to tweak it if you run multiple services in an ECS cluster: https://github.com/KariusDx/aws-scripts/blob/master/ecs-one-off

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants