Best Practice for Updating AWS ECS Service Tasks : <p>I'm currently attempting to set up a simple CI that will rebuild my project, create a new docker image, push the new image to an amazon ecr repo, create a new revision of an existing task definition with the latest docker image, update a running service with the new revision of the task definition, and finally stop the existing task running the old revision and start one running the new revision.</p>

<p>Everything is working fine except for starting the new revision of the task.</p>

<p>From a bash script, the final command I call is:</p>

<pre><code>aws ecs update-service --cluster "$CLUSTER" --service "$SERVICE" --task-definition "$TASK_DEFINITION":"$REVISION"
</code></pre>

<p>This results in an event error of:</p>

<pre><code>(service rj-api-service) was unable to place a task because no container instance met all of its requirements. The closest matching (container-instance bbbc23d5-1a09-45e7-b344-e68cc408e683) is already using a port required by your task.
</code></pre>

<p>And this makes sense because the container I am replacing is exactly sthe same as the new one and will be running on the same port, it just contains the latest version of my application.</p>

<p>I was under the impression the <code>update-service</code> command would stop the existing task, and start the new one, but it looks like it starts the new one first, and if it succeeds stops the old one.</p>

<p>What is the best practice for handling this? Should I stop the old task first? Should I just delete the service  in my script first and   recreate the entire service each update?</p>

<p>Currently I only need 1 instance of the task running, but I don't want to box my self in if I need this to be able to auto scale to multiple instances. Any suggestions on the best way to address this?</p>
