AWS ECS restart Service with the same task definition and image with no downtime : <p>I am trying to restart an AWS service (basically stop and start all tasks within the service) without making any changes to the task definition.</p>

<p>The reason for this is because the image has the <code>latest</code> tag attached with every build.</p>

<p>I have tried stopping all tasks and having the services recreate them but this means that there is some <code>temporarily unavailable</code> error when the services are restarting in my instances (2).</p>

<p>What is the best way to handle this? Say, A blue-green deployment strategy so that there is no downtime?</p>

<p>This is what I have currently. It'shortcomings is that my app will be down for a couple of seconds as the service's tasks are being rebuilt after deleting them.</p>

<pre><code>configure_aws_cli(){
    aws --version
    aws configure set default.region us-east-1
    aws configure set default.output json
}

start_tasks() {
    start_task=$(aws ecs start-task --cluster $CLUSTER --task-definition $DEFINITION --container-instances $EC2_INSTANCE --group $SERVICE_GROUP --started-by $SERVICE_ID)
    echo "$start_task"
}

stop_running_tasks() {
    tasks=$(aws ecs list-tasks --cluster $CLUSTER --service $SERVICE | $JQ ".taskArns | . []");
    tasks=( $tasks )
    for task in "${tasks[@]}"
    do
        [[ ! -z "$task" ]] &amp;&amp; stop_task=$(aws ecs stop-task --cluster $CLUSTER --task "$task")
    done
}

push_ecr_image(){
    echo "Push built image to ECR"
    eval $(aws ecr get-login --region us-east-1)
    docker push $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/repository:$TAG
}

configure_aws_cli
push_ecr_image
stop_running_tasks
start_tasks
</code></pre>
