Skip to main content
In this guide, you’ll learn how to update your application, rebuild and push a new Docker image to Docker Hub, and deploy the updated image using Amazon ECS. Follow along to modernize your deployment process and ensure seamless application updates.

Making Application Changes

Begin by modifying your application. For this demonstration, we update the HTML file by adding extra exclamation points to the H1 tag. The updated HTML file now appears as follows:
Next, build a new Docker image to incorporate your changes. Tag the image as “KodeKloud/ecs-project1” and execute the Docker build command. The console output may look similar to this:

Pushing the Updated Image

Once the Docker image is built successfully, push it to Docker Hub. During the push, you may notice that many layers already exist. Finally, the output provides a digest confirming a successful push:
Now that your image is updated on Docker Hub, it’s time to inform ECS of the new changes so that it pulls the latest image for your service.

Updating the ECS Service

Refreshing your application immediately after pushing the updated image may still display the old version. This happens because ECS hasn’t been notified of the change. To update your deployed service, follow these steps in the ECS Console:
  1. Navigate to Clusters and select your cluster.
  2. Choose the service you wish to update.
  3. Click on Update.
  4. Enable the Force New Deployment option.
Forcing new deployment instructs ECS to pull the latest image and replace the old tasks with new ones.
The diagram below shows the AWS ECS Task Details page, which provides essential information about running tasks, including network settings and container statuses:
The image shows an AWS ECS task details page, displaying information about a running task, including network settings and container status.
Additionally, observe the following diagram that illustrates a cluster with an active service:
The image shows an AWS ECS console displaying details of a cluster named "cluster1," with an active service called "project1-service" running on Fargate.
After applying the force deployment, ECS pulls the updated image and redeploys the tasks. Review the ECS Service Configuration screen as shown in the following diagram:
The image shows an AWS ECS configuration screen for setting up a service with details like task definition, launch type, operating system, and cluster information.
If you also modify the task definition file, a new revision of the task definition is created. For example, after updating “ecs-project1-taskdef”, the ECS console may display multiple revisions:
The image shows a web interface displaying task definitions for "ecs-project1-taskdef" with two active revisions listed.
Then, review the updated service configuration before finalizing the update:
The image shows an AWS ECS service configuration review screen, detailing settings like cluster, launch type, task definition, and network configuration. There is an option to update the service at the bottom.
After updating the service, ECS starts new tasks using the latest image while gradually shutting down the older tasks once the new ones pass all health checks. You can monitor this transition in the ECS Tasks view.

Verifying the Deployment

After the deployment, refresh the ECS service page and inspect one of the running tasks. Keep in mind that the task’s IP address changes with each new deployment. The diagram below illustrates the network details and container status of a running task:
The image shows an Amazon ECS console displaying details of a running task, including network information and container status.
Once you confirm the update on port 3000, you’ll notice the additional exclamation points in the H1 tag. However, be aware that changes in IP addresses could affect clients accessing the application directly.

The Role of a Load Balancer

A load balancer addresses the potential issue of changing IP addresses by providing a consistent endpoint. It automatically routes traffic to the updated task IP addresses after each deployment, ensuring uninterrupted client connectivity.
By integrating a load balancer, you simplify deployment updates while maintaining reliable access to your application, regardless of changes in the infrastructure.
For further reading on container orchestration and managing deployments, consider exploring the following resources:

Watch Video