amazon-web-servicesdockeramazon-ecsaws-fargate

How to run a one-off task on AWS ECS Fargate?


I need my personal project run one-off tasks on ECS with Fargate, like migration, app command etc.

The build and deploy pipelines are on Gitlab without job runners.

Are there are any possibilities to run a container and die after the command execution on ECS Fargate?


Solution

  • Yes.

    Fargate tasks can either run "standalone" or as part of an ECS service. The former are typically used for one-off / batch jobs, the latter are being used for long running apps (the ECS service will make sure a certain amount of tasks will always be running). See here for additional background. This isn't to say that the "standalone" mode can't execute long-running apps but simply there is no feedback loop with those and if they fail they will just stop.

    For your use case you want to run one of these "standalone" tasks with a docker command that executes and exits. This will stop the task when the commands finishes. I am not how you intend to run this task but this is the CLI method to run this "one-off" task instance. The equivalent exists for the various language bindings of the AWS SDKs.