I know this is an old thread, but the solution is much easier than most of the answers here make it out to be.
How to update the running container in two steps:
The below assumes you have a service running a task which is referencing a container tagged
latest (or any other static tag which doesn't change accross container updates).
- Upload your new container to the repository
- Manually kill your tasks
If the goal is for us to get a new build out into the wild, we don't really need to rely on our service for that (and I'd argue, we shouldn't rely on it). If you kill your task, the service will recognize it doesn't have the
Desired Count of tasks running, and simply spin up a new one. This will trigger a re-pull of your container, based on the same tag.
ECS services are HA security net, not a replacement for your CD/CI pipeline.
Bonus: If the goal is to have a service recognize a new container has been pushed (regardless of tags), we need to consider the implications of that. Do we really want a basic service controlling our deployment pipeline for us? Likely not. Ideally, you'll push your containers with different tags (based on release versions or something). In this case, the barrier to deployment is that the service has to be notified of something new -- again, it's a safety net for the service, and nothing more.
How to deploy new tags in three steps:
- Upload your new
container:tag to the repository
- Create a new task definition referencing the new
- Update your service to reference the new task definition
- Careful here! If you have
minimum healthy set to
0% as some other answers suggest, you're giving AWS full authority to kill your entire service in order to deploy the new task definition. If you prefer a rolling / gradual deployment, set your minimum to something
- Alternatively, set your
minimum healthy to
100% and your
maximum healthy to something
>100% to allow your service to deploy the new tasks before killing off the old ones (minimizing the impact to your users).
From this point, your service will automatically recognize you have specified a new task, and work on deploying that out based on the
maximum healthy thresholds you've configured.