AWS Certified Developer - Associate
Containers on AWS
Updating ECS Task Demo
In this lesson, we will explore different deployment options available within Amazon ECS. You will learn how to deploy a demo application on AWS Fargate, and then perform a seamless upgrade when a new version of the application becomes available.
Creating the Task Definition
Begin by navigating to the "Task Definitions" section in the AWS ECS console and create a new task definition:
- Name the task definition "web app."
- Select the launch type "AWS Fargate."
- Use the default task size settings, as this demo employs an Nginx container.
Next, configure the container settings. For this demo, the container image "my-dash-web-app" is available in three different versions (v1, v2, and v3). Start with version v1 and later update the service to version v2.
Ensure that the container listens on port 80, which is the default port for Nginx:
Keep the CPU resource settings at their default values:
Once all settings have been reviewed and confirmed, create the task definition.
Creating the ECS Service
With the task definition ready, you can now create your first ECS service within your cluster:
- Navigate to your main cluster and click "Create Service."
- Choose the launch type "Fargate."
- For the application type, select "Service" and use the "web app" task definition.
- Set the revision to version one (v1) and name your service "web app."
- Define the desired task count as five (i.e., five containers will run).
For deployment type, you can choose from the following:
- Rolling Update: Updates a few containers at a time until the new version is fully deployed.
- Blue-Green Deployment: Managed via CodeDeploy.
For this demo, select the Rolling Update option. With the minimum running tasks set at 100%, ECS ensures that five tasks remain running during updates. The maximum running tasks are set at 200%, allowing up to ten tasks (five existing plus five new) during a deployment.
Tip
If you lower the minimum running percentage (for example, to 50%), fewer tasks might run temporarily before the new version is fully deployed. For this tutorial, we maintain it at 100%.
Networking and Load Balancer Configuration
- In the networking section, retain the default subnets and VPC.
- Update the security group to allow HTTP access for the Nginx container.
- Create a load balancer to forward traffic to Nginx on port 80 and name it "web app - lb."
Establish a new listener on port 80 and configure a corresponding target group that utilizes the HTTP protocol.
After finalizing these settings, create the service. Once deployed, verify that five tasks are running by checking the ECS dashboard.
Verifying the Deployment
To confirm that your application has been successfully deployed:
- Click on the load balancer associated with the service.
- Copy the load balancer's DNS name.
- Open the DNS name in a web browser.
If version v1 is deployed correctly, you should see a page displaying "version one."
Updating the Service to Version Two
To update the application to version v2, follow these steps:
- Return to the ECS console and select the "web app" task definition.
- Create a new revision by updating the container image tag from v1 to v2.
- Update the service configuration to use revision two.
When updating the service:
- Select "Update" and then change the revision setting to two.
- Retain the same deployment settings (100% minimum and 200% maximum) to ensure that new tasks are fully deployed before the old ones are decommissioned.
- Click "Update" to trigger the deployment.
During the rollout, ECS will temporarily run up to 10 tasks (5 from version v1 and 5 from version v2). Once all new tasks are confirmed as running, ECS will gradually remove the older version (v1) tasks. Refresh the service dashboard to monitor the transition.
After the deployment completes, you should see that the running tasks now reference version v2 of the application.
Conclusion
This lesson demonstrated the following key steps:
- Creation of a task definition for an Nginx container.
- Deployment of an ECS service with load balancing on AWS Fargate.
- Use of a rolling update mechanism to perform a zero-downtime transition from version v1 to v2.
Next Steps
For more information on ECS deployments and best practices, explore the following resources:
Happy deploying!
Watch Video
Watch video content