Your container registry has 80,000 images and the storage bill keeps growing. What's your artifact retention strategy?

BeginnerScenarioPipelines at scale
Answer

Situation read → Most images are PR builds nobody will ever deploy again. Keep releases and what's running, expire the rest.

What I'd do →

  1. ECR lifecycle policies per repository:
{
  "rules": [
    { "rulePriority": 1, "description": "keep releases",
      "selection": { "tagStatus": "tagged", "tagPrefixList": ["v"], "countType": "imageCountMoreThan", "countNumber": 50 },
      "action": { "type": "expire" } },
    { "rulePriority": 2, "description": "expire untagged",
      "selection": { "tagStatus": "untagged", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 7 },
      "action": { "type": "expire" } },
    { "rulePriority": 3, "description": "expire old PR builds",
      "selection": { "tagStatus": "any", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 30 },
      "action": { "type": "expire" } }
  ]
}
  1. Make sure anything running in production or needed for rollback is protected (release tags with a high count, and deploys by tag that match the keep rule).
  2. Separate repositories or tag prefixes for dev builds and releases so rules are simple.

Why → Lifecycle rules run automatically; a one-off cleanup grows back in months.

Interview tip → Mention protecting rollback images; deleting the image you need to roll back to is a real incident.

All Real-World Interview questions Roadmap: Interview readiness

More on Pipelines at scale