Introduction
Your service runs a tested release. A new release should replace its tasks only after it can serve requests. In this lab, update a two-task ECS service to a healthy new image, diagnose a later release that runs but returns HTTP 503, and manually restore the original tested task definition.
Complete the previous ECS service lab first. This fresh VM supplies three immutable application images, application source, a base task-definition file, basic execution role, network and ALB. You register the revisions and manage the service yourself. No resources from an earlier VM or personal AWS account are required. Use the lower Terminal for commands and the upper AWS View for task revisions, deployment state, target health and real application responses. Keep one terminal open to retain your variables.
The two healthy images return release-1 and release-2 with HTTP 200. The deliberately broken image returns release-broken with HTTP 503, including at /health. The health path stays /health throughout; this fault belongs to the new application release.
Certification Relevance
| Certification | Exam skill | Practice |
|---|---|---|
| Developer – Associate (DVA-C02) | Skills 3.2.1 and 3.4.8 | Test deployed application responses and manually restore a tested release using an existing task-definition revision. |
This is the service release and restore portion of these skills; this lab does not configure a CI/CD pipeline or automatic deployment circuit breaker.
Lab Overview

Prepare a Tested Release
In this step, inspect the supplied images and register the first task-definition revision in your own cluster.
An ECS task definition is a versioned configuration. Registering another configuration in the same family creates a new revision, without editing the previous one. An image digest fixes the exact image bytes; a tag is a readable label. These three supplied tags are immutable and point to different digests.
Print the files and image inventory. The provided definition uses release-1 by digest, the basic execution role and the log settings from the previous labs:
cd /home/labex/project
cat task-definition.json
Inspect network.json:
cat network.json
Inspect the supplied ECR image inventory:
aws ecr describe-images \
--repository-name ct05-app \
--query 'imageDetails[].{Tags:imageTags,Digest:imageDigest}'
Expect release-1, release-2 and release-broken, each with a different sha256:... digest. Do not rebuild or overwrite these inputs; the lab focuses on releasing them through ECS.
Save the target group ARN and application URL. $(...) captures command output, and --output text produces an unquoted value:
TARGET_GROUP=$(aws elbv2 describe-target-groups \
--names ct05-app --query 'TargetGroups[0].TargetGroupArn' --output text)
echo "$TARGET_GROUP"
Save and display APPLICATION_URL:
APPLICATION_URL=$(cat application-url.txt)
echo "$APPLICATION_URL"
Create your cluster and register the provided definition. file:// reads the JSON file. ${DEFINITION_1##*/} removes the ARN prefix through its last slash, leaving the standard family:revision reference:
aws ecs create-cluster --cluster-name ct05-demo \
--query 'cluster.{Name:clusterName,Status:status}'
Save and display DEFINITION_1:
DEFINITION_1=$(aws ecs register-task-definition \
--cli-input-json file://task-definition.json \
--query 'taskDefinition.taskDefinitionArn' --output text)
echo "$DEFINITION_1"
Save and display REVISION_1:
REVISION_1=${DEFINITION_1##*/}
printf '%s\n' "$REVISION_1"
Expect ct05-demo:1. Save this reference: after testing it, you can return to the same configuration and exact image. AWS View shows your active cluster beside the supplied ct05-reference, with no service tasks yet.
Establish the Working Service
In this step, create two tasks from revision 1 and verify a working baseline before changing it.
The service requests two tasks and registers their port 8000 in the supplied IP target group. A 300-second grace period allows new tasks time to start before ECS acts on unhealthy checks. The ALB continues checking /health during that period. Here it also gives you time to inspect the controlled broken release later.
Create the service with your revision reference and supplied network:
aws ecs create-service \
--cluster ct05-demo --service-name ct05-app \
--task-definition "$REVISION_1" --desired-count 2 \
--launch-type FARGATE --network-configuration file://network.json \
--load-balancers "targetGroupArn=${TARGET_GROUP},containerName=app,containerPort=8000" \
--health-check-grace-period-seconds 300 \
--query 'service.{Name:serviceName,Desired:desiredCount,Definition:taskDefinition}'
Creation records your request. Wait for the service counts and then separately for target health; successful waiters produce no output:
aws ecs wait services-stable --cluster ct05-demo --services ct05-app
Wait for elbv2 target-in-service:
aws elbv2 wait target-in-service --target-group-arn "$TARGET_GROUP"
Inspect the ECS service configuration and counts:
aws ecs describe-services --cluster ct05-demo --services ct05-app \
--query 'services[0].{Desired:desiredCount,Running:runningCount,Pending:pendingCount,Definition:taskDefinition,Rollout:deployments[0].rolloutState}'
Inspect the registered targets and their health:
aws elbv2 describe-target-health --target-group-arn "$TARGET_GROUP" \
--query 'TargetHealthDescriptions[].{IP:Target.Id,State:TargetHealth.State}'
Expect desired/running 2, pending 0, revision 1, rollout COMPLETED and two healthy targets. Counts alone cannot prove the application works. Send four requests; the shell for loop repeats the same request, and curl -f fails on HTTP error responses:
for request in 1 2 3 4; do
curl -fsS "$APPLICATION_URL"
printf '\n'
done
All responses should show release-1, with two hostnames across these requests. In AWS View, click Request application to inspect a real response. This version is now a tested restore point.
Publish a Healthy New Revision
In this step, register revision 2 with a new image digest and update the existing service to use it.
A release changes the task definition's image, then tells the service which revision to run. Updating that service parameter starts a deployment. It does not modify already running containers in place.
Get the repository URI and the healthy new image digest. Build its digest reference in a shell variable:
REPOSITORY_URI=$(aws ecr describe-repositories \
--repository-names ct05-app --query 'repositories[0].repositoryUri' --output text)
echo "$REPOSITORY_URI"
Save and display DIGEST_2:
DIGEST_2=$(aws ecr describe-images --repository-name ct05-app \
--image-ids imageTag=release-2 --query 'imageDetails[0].imageDigest' --output text)
echo "$DIGEST_2"
Save and display IMAGE_2:
IMAGE_2="${REPOSITORY_URI}@${DIGEST_2}"
echo "$IMAGE_2"
jq edits JSON without changing the CPU, memory, role, port or log configuration. --arg supplies a string to its expression, and > writes the edited definition to a new file:
jq --arg image "$IMAGE_2" '.containerDefinitions[0].image = $image' \
task-definition.json > task-definition-2.json
Save and display DEFINITION_2:
DEFINITION_2=$(aws ecs register-task-definition \
--cli-input-json file://task-definition-2.json \
--query 'taskDefinition.taskDefinitionArn' --output text)
echo "$DEFINITION_2"
Save and display REVISION_2:
REVISION_2=${DEFINITION_2##*/}
echo "$REVISION_2"
Update the ECS service configuration and counts:
aws ecs update-service --cluster ct05-demo --service ct05-app \
--task-definition "$REVISION_2" \
--query 'service.{Requested:taskDefinition,Desired:desiredCount}'
Expect the requested definition to end in ct05-demo:2. During the rollout, old and new tasks can overlap. Healthy old tasks keep serving while the new tasks are checked. Wait and inspect the completed result:
aws ecs wait services-stable --cluster ct05-demo --services ct05-app
Wait for elbv2 target-in-service:
aws elbv2 wait target-in-service --target-group-arn "$TARGET_GROUP"
Inspect the ECS service configuration and counts:
aws ecs describe-services --cluster ct05-demo --services ct05-app \
--query 'services[0].{Requested:taskDefinition,Running:runningCount,Pending:pendingCount,Rollout:deployments[0].rolloutState}'
Save and display CURRENT_TASKS:
CURRENT_TASKS=$(aws ecs list-tasks --cluster ct05-demo \
--service-name ct05-app --desired-status RUNNING --query taskArns --output text)
echo "$CURRENT_TASKS"
Inspect the selected ECS tasks:
aws ecs describe-tasks --cluster ct05-demo --tasks $CURRENT_TASKS \
--query 'tasks[].{Status:lastStatus,Definition:taskDefinitionArn,Digest:containers[0].imageDigest}'
Repeat application requests to compare the task responses:
for request in 1 2 3 4; do
curl -fsS "$APPLICATION_URL"
printf '\n'
done
The unquoted $CURRENT_TASKS passes the two space-separated ARNs as separate --tasks arguments. Expect two running tasks using revision 2 and DIGEST_2, rollout COMPLETED, and only release-2 responses. Request again in AWS View: its response panel displays the most recent requested response, rather than automatically replacing earlier response text.
Diagnose a Release That Cannot Become Healthy
In this step, deploy the supplied broken image and distinguish the requested revision from the healthy version still serving traffic.
The broken image starts successfully but returns HTTP 503 at /health. A running task is not necessarily a healthy ALB target. Keep the same role, port, network and health path so you can isolate the application release as the fault.
Resolve its digest, edit a new definition and update the service:
BROKEN_DIGEST=$(aws ecr describe-images --repository-name ct05-app \
--image-ids imageTag=release-broken --query 'imageDetails[0].imageDigest' --output text)
echo "$BROKEN_DIGEST"
Save and display BROKEN_IMAGE:
BROKEN_IMAGE="${REPOSITORY_URI}@${BROKEN_DIGEST}"
echo "$BROKEN_IMAGE"
Write the configuration to task-definition-broken.json:
jq --arg image "$BROKEN_IMAGE" '.containerDefinitions[0].image = $image' \
task-definition.json > task-definition-broken.json
Save and display BROKEN_DEFINITION:
BROKEN_DEFINITION=$(aws ecs register-task-definition \
--cli-input-json file://task-definition-broken.json \
--query 'taskDefinition.taskDefinitionArn' --output text)
echo "$BROKEN_DEFINITION"
Save and display BROKEN_REVISION:
BROKEN_REVISION=${BROKEN_DEFINITION##*/}
echo "$BROKEN_REVISION"
Update the ECS service configuration and counts:
aws ecs update-service --cluster ct05-demo --service ct05-app \
--task-definition "$BROKEN_REVISION" \
--query 'service.taskDefinition'
Allow two five-second health checks, then inspect the deployment and target-health reasons:
sleep 12
aws ecs describe-services --cluster ct05-demo --services ct05-app \
--query 'services[0].{Requested:taskDefinition,Desired:desiredCount,Running:runningCount,Rollout:deployments[0].rolloutState,Reason:deployments[0].rolloutStateReason}'
aws elbv2 describe-target-health --target-group-arn "$TARGET_GROUP" \
--query 'TargetHealthDescriptions[].{IP:Target.Id,State:TargetHealth.State,Reason:TargetHealth.Reason}'
CURRENT_TASKS=$(aws ecs list-tasks --cluster ct05-demo \
--service-name ct05-app --desired-status RUNNING --query taskArns --output text)
echo "$CURRENT_TASKS"
aws ecs describe-tasks --cluster ct05-demo --tasks $CURRENT_TASKS \
--query 'tasks[].{Status:lastStatus,Definition:taskDefinitionArn,Digest:containers[0].imageDigest}'
Expect the service to request revision 3 with rollout IN_PROGRESS. Two healthy revision-2 tasks remain; two revision-3 tasks run but their targets become unhealthy with Target.ResponseCodeMismatch. This temporary overlap can produce running count 4 while desired count remains 2. If you wait beyond the grace period, ECS may replace the unhealthy tasks and briefly show initial targets; the release still cannot reach a healthy steady state.
Check both delivered logs and an ordinary application request:
aws logs filter-log-events --log-group-name /ecs/ct05 \
--filter-pattern '"503"' --query 'events[].message'
Request the application and inspect its response:
curl -i "$APPLICATION_URL"
The logs contain actual /health responses with status 503. The application request still returns HTTP 200 from release-2, because healthy old targets remain available. That response proves the old release works; it does not prove revision 3 succeeded. AWS View associates each target with its task-definition revision so you can compare the requested revision, healthy targets and response. Click Request application again.
Do not wait for this broken deployment to become stable: it cannot satisfy the health requirement. Do not change the health path or accept 503 as healthy. The next step restores a tested revision explicitly.

Restore the Original Tested Revision
In this step, manually restore revision 1 and prove that only its image serves after recovery.
A manual rollback selects an earlier task definition. You already tested revision 1 and retained its immutable image. This restores the previous application configuration; it does not undo database changes or external side effects.
Update the same service to your saved revision. No new task-definition registration is necessary:
aws ecs update-service --cluster ct05-demo --service ct05-app \
--task-definition "$REVISION_1" \
--query 'service.taskDefinition'
Wait for ecs services-stable:
aws ecs wait services-stable --cluster ct05-demo --services ct05-app
Wait for elbv2 target-in-service:
aws elbv2 wait target-in-service --target-group-arn "$TARGET_GROUP"
ECS starts replacement tasks from revision 1. It retires the superseded unhealthy tasks and then the healthy revision-2 tasks as the restored tasks pass their checks. Inspect the requested revision and actual running tasks:
aws ecs describe-services --cluster ct05-demo --services ct05-app \
--query 'services[0].{Requested:taskDefinition,Desired:desiredCount,Running:runningCount,Pending:pendingCount,Rollout:deployments[0].rolloutState}'
Save and display CURRENT_TASKS:
CURRENT_TASKS=$(aws ecs list-tasks --cluster ct05-demo \
--service-name ct05-app --desired-status RUNNING --query taskArns --output text)
echo "$CURRENT_TASKS"
Inspect the selected ECS tasks:
aws ecs describe-tasks --cluster ct05-demo --tasks $CURRENT_TASKS \
--query 'tasks[].{Status:lastStatus,Definition:taskDefinitionArn,Digest:containers[0].imageDigest}'
Inspect the registered targets and their health:
aws elbv2 describe-target-health --target-group-arn "$TARGET_GROUP" \
--query 'TargetHealthDescriptions[].{IP:Target.Id,State:TargetHealth.State}'
Repeat application requests to compare the task responses:
for request in 1 2 3 4; do
curl -fsS "$APPLICATION_URL"
printf '\n'
done
Expect desired/running 2, pending 0, rollout COMPLETED, two healthy revision-1 tasks and only release-1 responses. Their hostnames are new: rollback launches new containers from the retained definition and image rather than restarting the original stopped tasks.
Request the application again in AWS View. Stopped revision-2 and broken revision-3 tasks remain as history, but no longer execute or receive traffic. The service did not roll back automatically; your update-service selected the restore point.

Remove Your Service and Revisions
In this step, remove your service configuration and task execution while preserving the supplied images, ALB, role, network, logs and reference cluster.
Set desired count to zero first. Otherwise, stopping individual tasks would request replacements. Wait for the service to stop all tasks:
aws ecs update-service --cluster ct05-demo --service ct05-app \
--desired-count 0 --query 'service.desiredCount'
Wait for ecs services-stable:
aws ecs wait services-stable --cluster ct05-demo --services ct05-app
Delete the empty service, deregister all three revisions you registered, and delete your cluster. The loop limits deregistration to your saved definition ARNs:
aws ecs delete-service --cluster ct05-demo --service ct05-app \
--query 'service.status'
Deregister only the three saved task-definition revisions:
for definition in "$DEFINITION_1" "$DEFINITION_2" "$BROKEN_DEFINITION"; do
aws ecs deregister-task-definition --task-definition "$definition" \
--query 'taskDefinition.status'
done
Remove only the exercise ECS cluster:
aws ecs delete-cluster --cluster ct05-demo --query 'cluster.status'
These operations return INACTIVE. Confirm there is no remaining task execution or target registration, and preserve the reference cluster:
aws ecs list-tasks --cluster ct05-demo --desired-status RUNNING
Inspect the registered targets and their health:
aws elbv2 describe-target-health --target-group-arn "$TARGET_GROUP" \
--query 'TargetHealthDescriptions'
Inspect the exercise and reference cluster states:
aws ecs describe-clusters --clusters ct05-demo ct05-reference \
--query 'clusters[].{Name:clusterName,Status:status}'
Inspect the supplied ECR image inventory:
aws ecr describe-images --repository-name ct05-app \
--query 'imageDetails[].imageTags'
Expect no running task ARNs, no registered targets, ct05-demo inactive, ct05-reference active and all three supplied image tags still present. Delivered logs and stopped task history may remain. AWS View hides the former application response when no task is running. Do not delete the prepared ALB or reference resources to satisfy cleanup.
Summary
You registered immutable image-based task revisions, verified a normal service update, and diagnosed a later release whose running tasks failed real health checks. You distinguished the requested revision from the healthy version still serving, manually restored the original tested revision, and confirmed its task digests, target health and responses before removing your service and revisions.



