How to restart an AWS ECS service

Docker containers are easily one of my favorite pieces of new technology of the
last decade. They’ve immensely simplified how I work locally, no more virtual
machines, no more trying to keep my local development environment and production servers in parity, and no need for command-line sloths like nvm.

They’ve also changed how we deploy applications to production, going as far as
eliminating the need to run dedicated servers and simplifying the hell out of
clustering applications.

As far as containers have taken us over the years, containers do need to be
restarted between deployments from time to time. Memory leaks, gremlins in our code, and such, contribute to this need.

I typically use AWS Elastic Container Service (ECS) by way of AWS Fargate for micro services. However, one of my services has been experiencing a ghost in the machine, if you will.

Even so, executing an entire CI/CD pipeline to redeploy an ECS container tends to be over kill. Running linting, tests, and then finally deploying is time consuming and unnecessary when all you need to do is get things redeployed from an already tested and deployed image.

Thankfully, we don’t have to go through the usual CI/CD pipeline. Instead, we can simply update the service, and tell it to force a new deployment, as nothing
will actually be changing.

Steps to restart an AWS ECS instance in the AWS Console

This can be done via the AWS Console (direct links omitted as they are region
specific and I don’t want to add any unnecessary confusion):

  1. Log into the AWS Management Console.
  2. Go to Elastic Container Service.
  3. Go to Clusters.
  4. Click on the cluster that your service is in.
  5. Click on the service you’d like to restart.
  6. Click Update.
  7. Check Force new deployment about half way down the page.
  8. Click Skip to review.
  9. Click Update service.
  10. Wait patiently as your service restarts!

Steps to start an AWS ECS instance from the CLI

No much to it, but there are quite a few steps involved to make it happen. If
you’re a fan of the AWS CLI (as I am), you can accomplish everything outlined
above with this command:

aws ecs update-service --cluster :clusterName --service :serviceName --force-new-deployment
Zsh

You may still want to navigate out to ECS to monitor the status of the
deployment, that’s up to you.

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.