ECR image registry

Intermediate · 43 min

Private registries on AWS: login tokens, IAM and repository policies, tag immutability, lifecycle policies, scanning, replication and pull-through cache.

Before thisPolicy documents and evaluation logicWorkload identity for EC2, Lambda and CIVPC endpoints and PrivateLink

AWS Events · 43 min

ECR image registry

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by AWS EventsReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Each account has a private registry per Region. Repositories hold the images, and the Region is part of the image name.
  • Docker logs in with a temporary token from aws ecr get-login-password, valid for 12 hours. Your IAM permissions still decide what you can pull or push.
  • Turn on tag immutability for release repositories, and deploy by digest when you need to be certain what runs.
  • Lifecycle policies archive or expire old images. Preview them first, because they act on everything that matches.
  • Basic scanning finds operating system vulnerabilities. Enhanced scanning uses Amazon Inspector, covers language packages too and rescans as new findings appear.
  • Private subnets need the ecr.api and ecr.dkr interface endpoints plus an S3 gateway endpoint, since image layers come from S3.

Where the images live

Before ECS or EKS can run your container, the image has to be somewhere the machines can fetch it: quickly, reliably, and only if they’re allowed to. A public registry works until you need private images, access control tied to your cloud identities, or a guarantee that a scale-out at 3 a.m. won’t hit someone else’s rate limit.

Amazon Elastic Container Registry (ECR) is the registry inside your AWS account. It speaks the same OCI protocols as any other, so docker push and docker pull work as usual. This lesson covers what is specific to ECR; image names, tags and digests are covered under Docker.

Names and login

You get one private registry per Region, and you create repositories in it:

123456789012.dkr.ecr.eu-west-1.amazonaws.com/shop/api:1.4.0
\__account__/         \_Region_/            \_repo__/\_tag_/

Docker doesn’t know IAM, so you exchange your IAM identity for a password:

aws ecr get-login-password --region eu-west-1 |
  docker login --username AWS --password-stdin \
  123456789012.dkr.ecr.eu-west-1.amazonaws.com

The token is valid for 12 hours. It grants nothing extra: each push or pull is still checked against your permissions. In CI, get short-lived role credentials first through federation, never stored access keys. On ECS, the task execution role pulls the image; on EKS and plain EC2, the node or instance role does.

Access comes from IAM policies and, optionally, a repository policy attached to the repository. The second is how you let another account pull. ecr:GetAuthorizationToken is not tied to a repository, so it belongs in the caller’s IAM policy.

Tags you can trust

A tag is a movable label. If someone pushes 1.4.0 again, the next task to start may run different code from its neighbours. Tag immutability rejects a push to an existing tag; you can exclude patterns such as latest if you must.

On moto, a local emulator, I created an immutable repository, pushed a manifest as 1.4.0, then pushed a different manifest under the same tag. The second push was refused. moto named the error ImageAlreadyExistsException; AWS documents ImageTagAlreadyExistsException for this case, so match on the documented one.

Even so, a digest (@sha256:...) is the only name that cannot point elsewhere, so pipelines should record and deploy it.

Lifecycle policies

Every merge produces an image, and storage is billed per gigabyte-month. A lifecycle policy is a list of prioritised rules that expire or archive images:

{"rules": [
 {"rulePriority": 1, "description": "untagged after 14 days",
  "selection": {"tagStatus": "untagged", "countType": "sinceImagePushed",
                "countUnit": "days", "countNumber": 14},
  "action": {"type": "expire"}},
 {"rulePriority": 2, "description": "keep last 30 releases",
  "selection": {"tagStatus": "tagged", "tagPrefixList": ["v"],
                "countType": "imageCountMoreThan", "countNumber": 30},
  "action": {"type": "expire"}}
]}

A lower priority number wins, actions happen within 24 hours, and images referenced by a multi-platform index are not removed while the index exists. Run a preview before saving. A careless age rule can delete the image you’re currently running, and you find out at the next scale-out.

Scanning, signing, copying

Basic scanning looks for known vulnerabilities in operating system packages, on push or on demand. Enhanced scanning hands the job to Amazon Inspector, which also checks programming language packages, can scan continuously and emits EventBridge events. Findings are only useful if something acts on them; see scanning images. Managed signing can sign images as they are pushed.

Replication copies images to other Regions or accounts, configured at registry level; for another account, the destination must permit it. A pull-through cache rule mirrors an upstream registry such as Docker Hub, ECR Public, Quay or GitHub’s into your registry on first pull, so builds stop depending on the upstream for repeat pulls. Some upstreams need credentials stored in Secrets Manager. Repository creation templates give automatically created repositories your settings.

Pulling from private subnets

Tasks without internet access need VPC endpoints: ecr.api and ecr.dkr interface endpoints, and an S3 gateway endpoint, because layers are served from S3. Through a NAT gateway instead, every image pull is billed as NAT data processing. One catch from the docs: the first pull through a cache rule still needs a route to the internet.

About the video

The embed is AWS re:Invent 2023’s “Dive deep into Amazon ECR”, 43 minutes. Its chapters follow an image through the service: pushing, layer upload and manifest handling, pulling at scale, replication, scanning, lifecycle policies and public cache. It predates archive storage and managed signing. I judged it from chapters and description only, since transcripts couldn’t be fetched. English was judged from its English caption track and title. A hands-on push walkthrough is in deeper.

What was run: only the immutability check, on moto 5.1.22, an emulator. The login command needs Docker, which this lab lacked, and moto accepted the lifecycle policy, which says nothing about what it would expire. Token lifetime, scanning, lifecycle behaviour, pull-through cache and endpoints are from the AWS docs, checked 2026-11-29.

Where this fits

Images are stored. Next, describing how to run them with ECS task definitions and services.

Check yourself

  1. 01A CI job logged in to ECR yesterday and its push fails today. Why?

    The login token lasts 12 hours. Run get-login-password again at the start of each job, or use the ECR credential helper.

  2. 02An ECS task on Fargate in a private subnet with ECR interface endpoints still cannot pull. What is likely missing?

    The S3 gateway endpoint. The registry API and Docker endpoints answer the requests, but the layers themselves are downloaded from S3. Also check the task execution role and the endpoint security groups.

  3. 03Account B needs to pull from a repository in account A. What has to be true?

    Both sides must allow it. A repository policy in A grants B's principals the pull actions, and an IAM policy in B allows them, including ecr:GetAuthorizationToken.

  4. 04You expire images older than 30 days and a rollback later fails. What went wrong in the design?

    The rule counted age only, so it removed an image that was still deployed or was the rollback target. Prefer keeping the last N release tags, protect what is deployed, and preview the policy before applying it.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark