Lesson 4 of 4 Amazon ECS, Amazon EKS and Amazon ECR

Managing Amazon ECR Repositories

This lesson explains how operators manage access, lifecycle, scanning and replication of Amazon ECR repositories that store container images.

Learning outcomes

After completing this lesson, you will be able to:

  • Control repository access.
  • Configure lifecycle policies, scanning and replication.

Repositories and access

ECR private repositories are Regional. Clients authenticate with aws ecr get-login-password (a 12-hour token) or credential helpers, and IAM policies plus optional repository policies control push and pull, including cross-account pulls. Tag immutability prevents a tag such as v1.4.2 being overwritten, so deployments are reproducible. Images are encrypted with AES-256 or KMS. Private subnets need interface endpoints for ecr.api and ecr.dkr plus an S3 gateway endpoint, because image layers are stored in S3. Pull through cache rules cache images from public registries such as Docker Hub and ECR Public into a private repository.

Lifecycle policies, scanning and replication

Lifecycle policies expire images automatically by rules such as "keep only the last 30 images tagged prod-*" or "expire untagged images older than 14 days", controlling storage cost; a preview shows what would be deleted. Image scanning finds software vulnerabilities: basic scanning on push, or enhanced scanning with Amazon Inspector, which scans continuously and re-evaluates images when new CVEs are published. Replication copies images to other Regions and accounts automatically, so clusters in other Regions pull locally and images are available for disaster recovery.

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

The following diagram shows the three repository settings.

Managing an ECR repository. Lifecycle policies expire images by rule, such as keeping the last 30 prod-* images and expiring untagged images after 14 days. Enhanced scanning with Amazon Inspector re-evaluates images as new CVEs are published, and replication copies images to other Regions and accounts.
The rules and Regions are illustrative.
Scenario questions

Managing repositories

Exam skills 3.1.1 · 3.1.4

Choose the ECR feature for each requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

Images for a second Region

A company adds a DR Region for its ECS services. Rather than pushing every image twice from the build system, it configures ECR replication from the primary Region's registry to the DR Region for repositories with the prefix prod/. Inspector enhanced scanning is enabled in both Regions, and the same lifecycle policy is applied to replicated repositories so storage does not grow without limit.

Check yourself

Which setting prevents an image tag from being overwritten?

Show answer

Tag immutability.

Exam Tips

Remember for the exam

  • Lifecycle policies expire old or untagged images automatically.
  • Tag immutability prevents tags being overwritten.
  • Enhanced scanning uses Amazon Inspector for continuous vulnerability scanning.
  • Replication copies images across Regions and accounts.
  • Private subnets need ecr.api, ecr.dkr and S3 gateway endpoints to pull images.