Registry Model
Registry Model
ECR is a private, regional OCI registry: repositories hold image tags, and images are content-addressed layers shared across tags. Regional matters — CI pushes in us-east-1 do not automatically appear in eu-west-1; plan replication or build per region.
Three controls shape hygiene: tag mutability (IMMUTABLE prevents re-pushing an existing tag — the fix for "latest changed under us"), lifecycle policies (delete untagged images or cap count per repository so storage does not grow forever), and scan on push (basic scanning for known CVEs, or Enhanced scanning with Amazon Inspector for deeper coverage). Pull-through cache can front Docker Hub so CI does not lean on the public rate limits.
Push, Pull, Share
Push, Pull, Share
aws ecr get-login-password --region us-east-1 |
docker login --username AWS --password-stdin
123456789012.dkr.ecr.us-east-1.amazonaws.com
docker build -t myapp:abc123 .
docker tag myapp:abc123 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:abc123
docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:abc123
Tokens are short-lived (valid up to 12 hours), so CI should request one per pipeline run rather than caching it. Cross-account pulls use a repository policy granting ecr:GetDownloadTokenForLayer and friends to the other account's principal, plus a KMS key policy when the repository uses a CMK.
Pitfalls and Interview Focus
Pitfalls and Interview Focus
Lifecycle policies are aggressive by default of your rules: maxImageCount: 5 can delete an image that a running task still references — a new task then fails to pull during the next deploy. Exclude recent images or untagged-only rules during active rollouts.
Other traps: IAM auth works only where the principal's identity policy and the repository policy both allow — one missing side yields AccessDenied; latest plus mutable tags means deploys are unreproducible (pin digests or SHAs); scan-on-push reports arrive asynchronously, so a pipeline that checks findings immediately races the scanner.
Interview: describe promotion (build → scan gate → deploy by digest) and one control that prevents drift (immutable tags or lifecycle rules).
Quiz
1. Why set a repository to IMMUTABLE tags?
2. A cross-account pull fails with AccessDenied. What must you check?
3. What is the main risk of maxImageCount lifecycle rules during a rollout?
Flashcards
Question
Regional registry
Click to reveal answer
Answer
ECR repositories are regional — replicate or rebuild for multi-region deploys.
Question
Lifecycle policy
Click to reveal answer
Answer
Rules deleting untagged/old images or capping count — powerful, easy to over-apply.
Question
Auth flow
Click to reveal answer
Answer
get-login-password (12h token) → docker login → push; CI requests fresh tokens.
Question
Cross-account pull
Click to reveal answer
Answer
Repository policy + caller IAM (+ KMS key policy for customer-managed keys).
Question
Immutable tags
Click to reveal answer
Answer
Blocks tag re-pointing; pair with SHA tags for reproducible deploys.
Revision Notes
Key Takeaways
- 1. ECR is regional, tag policy and lifecycle rules are your governance levers
- 2. Both policy directions must allow cross-account pulls
- 3. Deploy by digest/SHA gated on scan results — not by a floating latest
Interview Tips
- • Describe image promotion end-to-end including the scan gate and digest pinning
- • Name a lifecycle-policy foot-gun and the rule you use to avoid it
Cheat Sheet
ECR: regional repos; immutable tags; scan-on-push; lifecycle rules (mind count caps). Push: get-login-password (12h). Cross-account = repo policy + IAM (+KMS). Deploy by digest after scan.