By the end you'll know
- What ECR, ECS and Fargate each do, and how a task definition, a task and a service fit together
- How to build an image for Arm, push it to a private repository, and read its vulnerability scan
- How a service keeps copies running behind a load balancer, and replaces one that dies
- How a rolling deployment ships a new version with no failed requests
- How the deployment circuit breaker rolls back a version that won't start
- Why the lab uses public subnets, and what real systems do instead
Before you start
- You need: the
juniper-ryeprofile, signed in, Lesson 20's virtual environment, and Docker running on your machine. This lesson builds on Lesson 12's load balancer and Lesson 8's network. - The script:
ecs-lab.pyfrom the practice folder'slesson-27. Everything it creates is namedjr-lesson27-*and taggedlesson=27, and itsdeletestep removes it, including the images on your machine. - How the script talks to AWS: through boto3, and to Docker on your machine through the
dockercommand. - To see every call the script makes that changes something, put
SHOW=1in front of any step. The "By hand" section has the same work with Docker and the AWS CLI. - Where you run things: your own machine, labeled (Your machine).
- Every output below is from real runs on November 15, 2026. The
fence,callandhealoutputs are from the first run of the day, so their task IDs differ from the rest.
This lab bills by the hour while it runs
The load balancer, the two copies and their public IP addresses cost about 6 cents an hour together, whether anyone calls the service or not. Run delete in the same sitting, and check if you stopped partway. Left running for a month, the same setup is about $45.
The short version
- ECR stores images; ECS runs them; Fargate supplies the computers, so there are no servers to patch.
- A task definition says what to run, a task is one running copy, and a service keeps a number of them running behind a load balancer.
- A deployment starts new copies first and stops old ones once the new ones pass health checks, so nothing fails.
- The circuit breaker rolls back a version that won't start, after 3 failed starts here.
- Tags in the repository are immutable, so
v2always means the same image.
What this lesson costs
| Part | Cost, in us-east-2 |
|---|---|
| Two copies on Fargate, Arm, 0.25 vCPU and 0.5 GB each | $0.0099 an hour each |
| The Application Load Balancer | $0.0225 an hour, plus a little for traffic |
| Four public IPv4 addresses | $0.005 an hour each |
| The images in ECR, about 43 MB each | $0.10 per GB a month: a fraction of a cent |
| This lesson, about 2 hours | About 12 cents, from credits |
Containers, and where they run on AWS
A container image is an app packed with everything it needs to run: the language, the libraries, the code, and the command that starts it. The same image runs the same way on your laptop and on AWS. What AWS adds is a place to keep images, and something to run them, keep them running, and replace them when a new version ships.
| Part | Is | In the lab |
|---|---|---|
| ECR (Elastic Container Registry) | A private store for images | One repository, three versions |
| ECS (Elastic Container Service) | AWS's service that runs and watches containers | One cluster, one service |
| Fargate | Computers for ECS that AWS manages: you pick CPU and memory, not servers | 0.25 vCPU and 0.5 GB per copy, on Arm |
| Cluster | A name that groups services; with Fargate, nothing more | jr-lesson27 |
| Task definition | What to run: image, CPU, memory, ports, roles, logs. Each change is a new revision | Revisions 4, 5 and 6 |
| Task | One running copy of a task definition | Two at a time |
| Service | Keeps a number of tasks running, registered with a load balancer, and ships new revisions | 2 copies, across 2 zones |
ECS, EKS, or your own machine?
ECS is one of two ways to run containers on AWS. The other is EKS (Elastic Kubernetes Service), AWS's Kubernetes, in Lesson 29. And before either, containers run on your own machine, with Docker or with Kubernetes in kind. The three are easy to mix up, and they answer different questions.
| Your own machine | ECS | EKS | |
|---|---|---|---|
| What it is | Docker, or Kubernetes in kind | AWS's own container service | Kubernetes, run by AWS |
| Can you install it yourself? | Yes: that's the point | No: it only exists in AWS | Kubernetes, yes (kind, kubeadm); EKS itself, no |
| What you pay just to have it | Nothing | Nothing: you pay for Fargate or servers | $0.10 an hour per cluster, about $73 a month, before any computers |
| What you look after | Everything, and only while the laptop is on | Task definitions and services | The cluster's versions and add-ons, nodes, and Kubernetes objects |
| Learning curve | Low | Low to medium | High |
| Works outside AWS | Yes | No | Yes: it's standard Kubernetes |
| Good for | Building and testing | Running containers on AWS with the least to learn | Teams that want Kubernetes and its tools everywhere |
Your own machine is for building, not for running. Nobody else can reach it, it stops when the lid closes, and one laptop is one failure away from being down. Moving to AWS gets you an address others can reach, copies in more than one zone, a load balancer, and a service that replaces copies that fail, as this lesson shows.
ECS is the shorter path. There's no cluster to upgrade and nothing to pay for ECS itself, and it fits closely with AWS's load balancers, roles and logs. The catch is that it only exists in AWS: what you learn and write for it doesn't move to another cloud or to your laptop.
EKS gives you Kubernetes, with everything that comes with it. The same manifests run in kind on your laptop, on EKS and on other clouds, and tools like Helm and Argo CD work anywhere Kubernetes does. In exchange, there's a cluster fee, a Kubernetes version to upgrade a few times a year, and much more to learn.
Which one?
- A few services, on AWS, a small team: ECS. For the bakery's menu, this is the right choice.
- Many services, a platform team, or more than one cloud: EKS.
- The team already runs Kubernetes, or is hiring for it: EKS.
- Just building or testing: your own machine. Docker for one container, kind when you're learning Kubernetes.
A common mistake is choosing EKS because Kubernetes is popular, then spending months running the cluster when ECS would have done the job. Choose by what the team needs to run and what it already knows. Lesson 29 builds the same menu service on EKS, so you can compare the two directly.
Can you do the lab, and what it costs
(Your machine)
cd ~/Apps/aws-practice/lesson-27
source ../lesson-20/.venv/bin/activate
python ecs-lab.py fence
== Is Docker running on your machine?
yes: linux/arm64 29.9.2
== Can this account do the lab in us-east-2?
ECR allowed
ECS allowed
Elastic Load Balancing allowed
EC2 networking allowed
VPCs in this Region: 1 (the lab makes its own, so it doesn't touch them)
== What it costs in us-east-2 (from the Price List API)
Fargate on Arm, per vCPU an hour $0.03238 per hours
Fargate on Arm, per GB of memory an hour $0.00356 per hours
Application Load Balancer, an hour $0.0225 per Hrs
Public IPv4 address in use, an hour $0.005 per Hrs
ECR storage, per GB a month $0.1 per GB-Mo
== While it runs: about $0.062 an hour
2 copies of 0.25 vCPU and 0.5 GB: $0.0099 an hour each
the load balancer: $0.0225 an hour, plus a little for traffic
4 public IPv4 addresses (one per copy, two for the load balancer): $0.020 an hour
a 2-hour sitting: about $0.12, from credits
The load balancer costs more than both copies together, and the four public IP addresses cost as much as both copies too. For a small service, the computers are the cheap part. Fargate on Arm (Graviton) is about 20% cheaper than on Intel for the same size, which is why the lab builds for Arm.
Build and store the image
python ecs-lab.py image
== A private repository: tags can't be overwritten, every push is scanned, old images expire
== Building v1 on your machine and pushing it
built jr-lesson27-menu:v1 for linux/arm64 in 1 seconds, 202 MB on your machine
pushed to (your registry)/jr-lesson27-menu:v1 in 6 seconds
== In ECR: v1 is 43 MB compressed, digest sha256:a9d8e8d9de8b...
== The scan
this registry's scanning: basic, 0 registry-level rules
scan complete after 10 seconds, started on push
findings: high 4, medium 10, low 3, undefined 1
high CVE-2026-76844 in zlib
high CVE-2026-85091 in zlib
high CVE-2026-5435 in glibc
== Trying to push v1 again (tags are immutable)
accepted: the same image was already there, so nothing changed
The image is a small Python web server on top of the official python:3.13-slim image, which the Dockerfile pulls from ECR Public rather than Docker Hub, to avoid Docker Hub's download limits:
FROM public.ecr.aws/docker/library/python:3.13-slim
WORKDIR /app
COPY app.py .
ARG VERSION=v1
ARG CRASH=0
ENV APP_VERSION=$VERSION CRASH=$CRASH PYTHONUNBUFFERED=1
USER 1000
EXPOSE 8080
CMD ["python", "app.py"]
| In the output | Shows |
|---|---|
| 202 MB on your machine, 43 MB in ECR | Images are stored and sent compressed, in layers. v2 and v3 pushed in 1 second because only the small top layer changed. |
| 4 high findings, none in the app's code | All are in libraries the base image ships with, like zlib and glibc |
| The second push of v1: accepted | Immutable tags stop a tag from pointing at a different image; pushing the identical image changes nothing |
USER 1000 | The app runs as an ordinary user, not root, inside the container |
A scan that finds things in a base image is normal, not a reason to panic, and not a reason to ignore it. The fix is almost never in your code: rebuild on the newest base image regularly, so the libraries' fixes reach you, and use smaller bases that ship less to begin with. Basic scanning is free and checks the operating system's packages when you push. Enhanced scanning, through Amazon Inspector, also checks language packages and rescans as new vulnerabilities are published, at a cost per image.
Immutable tags mean v2 is the same image forever. Without them, someone can push a different image as v2, and copies started before and after it run different code under the same name. The repository also has a lifecycle policy: untagged images go after a day, and only the newest five are kept, so old images don't pile up storage costs.
Run it: network, load balancer, service
In the console: Elastic Container Service > Clusters > Create cluster, then Task definitions > Create new task definition, then in the cluster, Services > Create.
python ecs-lab.py build
== A network of its own: 10.27.0.0/16, two public subnets in two zones
== Security groups: the load balancer takes port 80 from your IP/32 only; the tasks take 8080 from the load balancer only
== An Application Load Balancer across both zones, health checks on /health every 10 seconds
active after 121 seconds
== A cluster: just a name to group services; Fargate brings the computers
== Two roles: one for ECS to pull the image and write logs, one for the app itself (it needs nothing)
== Task definition jr-lesson27-menu:4: 0.25 vCPU, 0.5 GB, Arm, image v1, port 8080, logs to CloudWatch
== A service: keep 2 copies running, spread across both zones, behind the load balancer
waiting until both copies pass their health checks...
stable after 62 seconds
== jr-lesson27-menu: 2 of 2 running, task definition revision 4
task 7e7bb76f us-east-2a running started 13:29:58
task c2218f8f us-east-2b running started 13:29:37
== The address: http://jr-lesson27-alb-333528411.us-east-2.elb.amazonaws.com (open only to your IP)
The first task definition was revision 4, not 1. An earlier run that day used 1 to 3, and even after they were deleted, ECS never reuses a revision number. That's deliberate: "revision 4" always means one exact set of settings, the same idea as immutable image tags.
The task definition's heart:
ecs.register_task_definition(
family="jr-lesson27-menu", networkMode="awsvpc", requiresCompatibilities=["FARGATE"],
cpu="256", memory="512",
runtimePlatform={"cpuArchitecture": "ARM64", "operatingSystemFamily": "LINUX"},
executionRoleArn=exec_role, taskRoleArn=task_role,
containerDefinitions=[{
"name": "menu", "image": "(your registry)/jr-lesson27-menu:v1", "essential": True,
"portMappings": [{"containerPort": 8080}],
"logConfiguration": {"logDriver": "awslogs", "options": {
"awslogs-group": "/ecs/jr-lesson27-menu", "awslogs-region": "us-east-2",
"awslogs-stream-prefix": "menu"}}}])
| Part | Why |
|---|---|
| Two roles | The execution role is for ECS: pull the image, write logs. The task role is for the app's own calls to AWS. Mixing them gives the app permissions it doesn't need. |
cpu="256", memory="512" | A quarter of a vCPU and half a GB: Fargate's smallest size, and plenty for a menu |
awsvpc networking | Each task gets its own network card, IP address and security group |
Health checks on /health | The load balancer only sends requests to copies that answer it |
| Two zones | ECS spreads the copies across zones, so one zone failing leaves a copy running (Lesson 13) |
Why public subnets? Each task has to download its image from ECR when it starts. In a private subnet that needs a NAT gateway, $32.85 a month before any data, as last lesson's checker priced it, or VPC endpoints for ECR, S3 and CloudWatch Logs, which also cost by the hour. For a lab, public IP addresses on the tasks are far cheaper, and the tasks' security group still only accepts the load balancer. Real systems put tasks in private subnets; see "In real systems".
Two copies, one address
python ecs-lab.py call
== GET / ten times
first answer: {"bakery": "Juniper & Rye", "version": "v1", "task": "1a883df2", "menu": [{"item": "sourdough", "price": 6.0}, {"item": "rye", "price": 7.0}, {"item": "croissant", "price": 3.5}, {"item": "baguette",
v1 task 1a883df2 answered 5
v1 task 3bea3be2 answered 5
Ten calls to one address, split five and five between the two copies. Each copy reads its own task ID from the ECS metadata endpoint, a local address every task can ask about itself, and includes it in its answer, which is how the split shows.
Ship v2 with no downtime
python ecs-lab.py deploy
== Building v2 and pushing it
built jr-lesson27-menu:v2 for linux/arm64 in 1 seconds, 202 MB on your machine
pushed to (your registry)/jr-lesson27-menu:v2 in 1 seconds
== Rolling out task definition revision 5 (image v2): new copies start first, old ones stop once new ones are healthy
1s primary rev 5: 0 running; active rev 4: 2 running v1 v1 v1 v1 v1 v1
12s primary rev 5: 0 running; active rev 4: 2 running v1 v1 v1 v1 v1 v1
23s primary rev 5: 0 running; active rev 4: 2 running v1 v1 v1 v1 v1 v1
34s primary rev 5: 0 running; active rev 4: 2 running v1 v1 v1 v1 v1 v1
45s primary rev 5: 1 running; active rev 4: 2 running v2 v1 v1 v1 v2 v2
56s primary rev 5: 1 running; active rev 4: 2 running v1 v1 v1 v1 v2 v2
67s primary rev 5: 1 running; active rev 4: 2 running v1 v1 v1 v2 v1 v2
78s primary rev 5: 2 running; active rev 4: 2 running v2 v1 v2 v2 v1 v2
89s primary rev 5: 2 running; active rev 4: 2 running v2 v2 v1 v1 v2 v1
100s primary rev 5: 2 running; active rev 4: 1 running v1 v2 v2 v1 v2 v1
111s primary rev 5: 2 running; active rev 4: 1 running v2 v2 v2 v1 v2 v1
122s primary rev 5: 2 running; active rev 4: 0 running v2 v2 v1 v2 v2 v2
133s primary rev 5: 2 running; draining rev 4: 0 running v2 v2 v2 v2 v2 v2
144s primary rev 5: 2 running; draining rev 4: 0 running v2 v2 v2 v2 v2 v2
155s primary rev 5: 2 running; draining rev 4: 0 running v2 v2 v2 v2 v2 v2
166s primary rev 5: 2 running; draining rev 4: 0 running v2 v2 v2 v2 v2 v2
177s primary rev 5: 2 running; draining rev 4: 0 running v2 v2 v2 v2 v2 v2
188s primary rev 5: 2 running v2 v2 v2 v2 v2 v2
== Done: v1 46, v2 62
108 calls during the rollout, and every one was answered. For about 80 seconds, both versions answered side by side. That's the trade of a rolling deployment: no downtime, but for a while two versions run at once, so a new version must work alongside the old one. A change that breaks that, like renaming a database column both versions read, needs to ship in steps.
| Seconds | What happened |
|---|---|
| 0 to 45 | Two v2 copies started: found a computer, pulled the image, started, passed two health checks |
| 45 to 78 | The load balancer sent traffic to each new copy as it turned healthy |
| 78 to 122 | With two healthy v2 copies, ECS stopped the v1 copies one at a time |
| 122 to 188 | The old deployment drained and was cleaned up |
Two settings make it work. minimumHealthyPercent=100 says never drop below 2 healthy copies, so the old ones stay until the new ones are ready. maximumPercent=200 allows up to 4 copies during the change, so the new ones can start alongside. When a v1 copy is stopped, the load balancer first gives it 10 seconds to finish requests already in progress, the deregistration delay; the default is 5 minutes.
Ship a broken v3
v3 exits as soon as it starts, as an app does when a setting it needs is missing.
python ecs-lab.py break
== Building v3, which exits on start because a setting is missing, and pushing it
built jr-lesson27-menu:v3 for linux/arm64 in 1 seconds, 202 MB on your machine
pushed to (your registry)/jr-lesson27-menu:v3 in 1 seconds
== Rolling out revision 6 (image v3), with the deployment circuit breaker on
0s primary rev 6: 0 running; active rev 5: 2 running v2 v2 v2 v2 v2 v2
11s primary rev 6: 0 running; active rev 5: 2 running v2 v2 v2 v2 v2 v2
22s primary rev 6: 0 running; active rev 5: 2 running v2 v2 v2 v2 v2 v2
33s primary rev 6: 0 running; active rev 5: 2 running v2 v2 v2 v2 v2 v2
44s primary rev 6: 0 running; active rev 5: 2 running v2 v2 v2 v2 v2 v2
55s primary rev 6: 0 running; active rev 5: 2 running v2 v2 v2 v2 v2 v2
66s primary rev 6: 0 running; active rev 5: 2 running v2 v2 v2 v2 v2 v2
77s primary rev 6: 1 running; active rev 5: 2 running v2 v2 v2 v2 v2 v2
88s primary rev 6: 0 running, 1 failed; active rev 5: 2 running v2 v2 v2 v2 v2 v2
99s primary rev 6: 0 running, 1 failed; active rev 5: 2 running v2 v2 v2 v2 v2 v2
110s primary rev 6: 0 running, 1 failed; active rev 5: 2 running v2 v2 v2 v2 v2 v2
121s primary rev 6: 0 running, 1 failed; active rev 5: 2 running v2 v2 v2 v2 v2 v2
132s primary rev 6: 0 running, 1 failed; active rev 5: 2 running v2 v2 v2 v2 v2 v2
143s primary rev 6: 0 running, 1 failed; active rev 5: 2 running v2 v2 v2 v2 v2 v2
154s primary rev 6: 0 running, 2 failed; active rev 5: 2 running v2 v2 v2 v2 v2 v2
165s primary rev 6: 0 running, 2 failed; active rev 5: 2 running v2 v2 v2 v2 v2 v2
176s primary rev 5: 2 running; active rev 6: 0 running, 3 failed v2 v2 v2 v2 v2 v2
187s primary rev 5: 2 running; draining rev 6: 0 running, 3 failed v2 v2 v2 v2 v2 v2
198s primary rev 5: 2 running; draining rev 6: 0 running, 3 failed v2 v2 v2 v2 v2 v2
209s primary rev 5: 2 running; draining rev 6: 0 running, 3 failed v2 v2 v2 v2 v2 v2
220s primary rev 5: 2 running; draining rev 6: 0 running, 3 failed v2 v2 v2 v2 v2 v2
231s primary rev 5: 2 running; draining rev 6: 0 running, 3 failed v2 v2 v2 v2 v2 v2
242s primary rev 5: 2 running v2 v2 v2 v2 v2 v2
253s primary rev 5: 2 running v2 v2 v2 v2 v2 v2
== Back on revision 5 (image v2); while it happened: v2 144
== What the service's events said (newest last)
13:36:09 (service jr-lesson27-menu) (deployment ecs-svc/6886124089109971319) deployment failed: tasks failed to start.
13:36:09 (service jr-lesson27-menu) rolling back to deployment ecs-svc/5897631766626896460.
13:37:21 (service jr-lesson27-menu) (deployment ecs-svc/5897631766626896460) deployment completed.
== 4 copies of v3 started and failed; one of them: exit code 1; Essential container in task exited
its log: menu: MENU_TABLE is not set; refusing to start
== Keeping v3's task definition out of the way
revision 6 deregistered: nothing can start it by mistake
Every one of the 144 calls got v2. The broken version never received a request, because it never passed a health check, and the old copies were never stopped, because minimumHealthyPercent=100 keeps them until new ones are healthy. That setting is what made a bad deploy harmless.
The circuit breaker rolled back after 3 failed starts, with no one watching. Its limit is half the service's copies, but never fewer than 3, so 3 for this service. Without it, ECS would keep starting v3 copies forever, and the deployment would never finish or fail. The "4 copies" in the summary is one more than the counter's 3: a fourth had started when the rollback began, and was stopped.
The reason came from three places, and that's the troubleshooting order for a service that won't deploy:
| Look at | Told you |
|---|---|
| The service's events | That the deployment failed because tasks failed to start, and was rolled back |
| The stopped task | Exit code 1, "Essential container in task exited": the app quit, it wasn't killed |
| The container's log | Why: MENU_TABLE is not set |
The script then deregistered revision 6, so no one can start the broken version by mistake. Deregistering keeps it for reference; tasks already using a revision aren't affected.
Stop a copy, and watch it come back
python ecs-lab.py heal
== Stopping task 0328eb7f by hand, as if its computer had failed
a replacement, task 932d49b3, was running after 68 seconds
and passing health checks after 68 seconds
== Calls while it happened: v2 52
The service's job is to keep 2 copies running, so when one stopped, it started another, with no one asking. For those 68 seconds the other copy answered all 52 calls. A service of one copy would have been down for the whole time, which is why even small services run two.
Take it down
In the console: in the cluster, delete the service, then the cluster; deregister and delete the task definitions; then in EC2, delete the load balancer, then its target group; then the repository in ECR, the roles, the log group and the VPC.
python ecs-lab.py delete
== Deleting the service (its copies stop first)
== Deleting 3 task definition revisions
== Deleting the cluster
== Deleting load balancer jr-lesson27-alb and its listener
== Deleting the target group
deleted
== Deleting the log group
== Deleting role jr-lesson27-execution-role
== Deleting role jr-lesson27-task-role
== Deleting the repository and its images
== Deleting the network (waiting for the load balancer's network cards to go)
gone after 15 seconds
== Removing 6 image tags from your machine, and the registry login
== Anything left from Lesson 27
nothing: all clear
On the first run of the day, delete failed here, even though the load balancer was already gone:
== Deleting the target group
AWS said: An error occurred (ResourceInUse) when calling the DeleteTargetGroup operation: Target group '(an ARN) is currently in use by a listener or a rule
The target group stayed "in use" for over 20 minutes after its load balancer was deleted, and in that time build couldn't attach it to a new load balancer either: a target group can belong to only one. Nothing was wrong except timing. AWS's view of a deletion can take a while to reach every part of the service, and code that cleans up has to expect it. The script now retries for 5 minutes and then says to run delete again later, rather than failing. Terraform, in Lesson 28, retries the same way.
By hand: the same work with Docker and the AWS CLI
(Your machine) Build for Arm, sign Docker in to your registry, and push:
export AWS_PROFILE=juniper-rye AWS_REGION=us-east-2
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
REGISTRY=$ACCOUNT.dkr.ecr.us-east-2.amazonaws.com
aws ecr create-repository --repository-name jr-lesson27-menu \
--image-tag-mutability IMMUTABLE --image-scanning-configuration scanOnPush=true
docker build --platform linux/arm64 --build-arg VERSION=v1 -t $REGISTRY/jr-lesson27-menu:v1 build
aws ecr get-login-password | docker login --username AWS --password-stdin $REGISTRY
docker push $REGISTRY/jr-lesson27-menu:v1
aws ecr describe-image-scan-findings --repository-name jr-lesson27-menu --image-id imageTag=v1 \
--query "imageScanFindings.findingSeverityCounts"
Ship a new revision, and read the service's events:
aws ecs update-service --cluster jr-lesson27 --service jr-lesson27-menu --task-definition jr-lesson27-menu:5
aws ecs wait services-stable --cluster jr-lesson27 --services jr-lesson27-menu
aws ecs describe-services --cluster jr-lesson27 --services jr-lesson27-menu \
--query "services[0].events[:5].[createdAt,message]" --output table
Find why a task stopped:
TASK=$(aws ecs list-tasks --cluster jr-lesson27 --desired-status STOPPED --query "taskArns[0]" --output text)
aws ecs describe-tasks --cluster jr-lesson27 --tasks $TASK \
--query "tasks[0].[stoppedReason,containers[0].exitCode]"
In real systems
- Tasks run in private subnets, reaching ECR through VPC endpoints or a NAT gateway, with only the load balancer public.
- The load balancer serves HTTPS, with a certificate from ACM (Lesson 14), and redirects plain HTTP.
- Images are tagged with the commit they were built from, never
latest, and built and pushed by a pipeline (Lesson 31), not a laptop. - All of this is Terraform (Lesson 28): network, load balancer, roles, cluster, task definition and service in reviewed code.
- Services scale with load, with target tracking on CPU or requests per copy, and can use Fargate Spot for work that can be interrupted, at up to 70% off.
- Secrets come from Secrets Manager (Lesson 34), referenced in the task definition, never baked into the image.
- Base images are rebuilt weekly so library fixes arrive, and scan findings are triaged, not ignored.
Spot the problem
Work out what's wrong before you read the explanation.
"Two copies, two different menus." A team tags every build latest and points the task definition at menu:latest. One Tuesday, customers see the new prices on some page loads and the old ones on others, though no one deployed anything. What's wrong? latest is a moving tag: a copy that restarted pulled whatever latest pointed at by then, while the other kept the image it started with, so the service ran two versions under one task definition. The fix: tag each image with its version or commit, make the repository's tags immutable, and ship by registering a new revision; then every copy of a revision runs the same image. Then check: try pushing a different image with an existing tag; does ECR refuse it, and do all running tasks of a revision show the same image digest?
Keep this
| Remember | Why |
|---|---|
| Task definition, task, service | What to run, one copy, keep N running |
| Two copies, two zones | A copy stopped; the other answered all 52 calls |
| New copies first, old ones after | 108 calls during v2's rollout, none failed |
| Circuit breaker with rollback | v3 rolled back after 3 failed starts |
| Events, stopped task, then logs | Where "it won't deploy" gets its answer |
Immutable tags, never latest | One name, one image |
| Execution role vs task role | ECS's permissions vs the app's |
| The load balancer is the big cost | $0.0225 an hour vs $0.0099 per copy |
| Deletions take time to settle | A target group stayed "in use" 20 minutes |
Where you are now
Juniper & Rye's menu runs in containers: built on your machine, stored in ECR with immutable tags and a scan on every push, and run as two copies on Fargate behind a load balancer only you can reach. v2 shipped with no failed calls, a broken v3 was rolled back by itself, and a stopped copy was replaced in 68 seconds. Building it took a script of several hundred lines and a careful delete order. Next, Lesson 28 builds this same service with Terraform, which works out the order itself, and keeps track of what it made.
Check yourself
What does an ECS service add on top of a task definition?
During v2's rollout, why did no call fail?
Why did the broken v3 never answer a call?
Where did the reason for v3's failure finally show?
Pushing the same v1 image again was accepted. What do immutable tags prevent?
Why does the app have its own task role, separate from the execution role?
Why did the lab use public subnets for the tasks?
Key terms
- Container image: an app packed with what it needs to run, in layers.
- ECR (Elastic Container Registry): AWS's private store for images.
- ECS (Elastic Container Service): AWS's service that runs and watches containers.
- Fargate: computers for ECS that AWS manages, sized by CPU and memory.
- Task definition: what to run: image, size, ports, roles and logs; each change is a new revision.
- Task: one running copy of a task definition.
- Service: keeps a number of tasks running behind a load balancer and ships new revisions.
- EKS (Elastic Kubernetes Service): Kubernetes, run by AWS.
- Execution role: lets ECS pull the image and write logs.
- Task role: the app's own permissions for calling AWS.
- Rolling deployment: replacing copies a few at a time, new ones first.
- Deployment circuit breaker: stops a deployment whose tasks keep failing, and can roll it back.
- Immutable tag: an image tag that can't be pointed at a different image.
Go deeper
- AWS: ECS task definition parameters (opens in a new tab), and the deployment circuit breaker (opens in a new tab).
- AWS: ECR image scanning (opens in a new tab), and Fargate pricing (opens in a new tab).
- Docker track: building images. Kubernetes track: Deployments, the same rolling update idea in Kubernetes.
- Try: run
build, then in the console open the service, choose Update service, and set 3 desired tasks; watch which zone the third copy lands in. Then runbreakand, while it runs, open the service's Deployments tab to watch the circuit breaker there. Rundeletewhen you're done.