Set a lifecycle policy

Give a repository its own rules for deleting old images, go back to the organization default, or let nothing expire.

Last updated 18 November 2026View as Markdown

How rules decide is in Lifecycle policies. Replace repository-id with the repository's id.

Warning

From the next hourly run, the images the policy selects are deleted. With softDeleteDays 0 they cannot be restored.

Prerequisites

  • Permission for ecr:PutLifecyclePolicy on the repository; to remove its own policy, ecr:DeleteLifecyclePolicy.
  • To see the policy and its dry run: ecr:GetLifecyclePolicy on the repository. Without it the console's Lifecycle policy tab says so.
  • In the console, also ecr:DescribeRepositories on the repository; without it its page answers 404.

Set the policy

  1. Open Image repositories, then open the repository.
  2. Open the Lifecycle policy tab.
  3. Turn on Customize for this repository. The rules start as a copy of the organization default.
  4. Edit the rules: under Always keep, what is never deleted; under Then delete, in this order, the rules (Add rule); under Undo window, how many days deleted images stay restorable. Or choose Advanced (JSON) and paste a policy, an AWS ECR one included.
  5. Check Dry run: what this policy would do now: every image with whether it would be deleted and what decides it.
  6. Choose Save policy.

Turning Customize for this repository off again makes the repository use the organization default at once, without Save policy. Without ecr:PutLifecyclePolicy the switch and the rules are read-only.

In the example, rule 2 also keeps the 30 newest v* images away from any later rule. An AWS ECR policy is stored as you sent it, and its deleted images stay restorable for 7 days.

Go back to the default, or let nothing expire

  1. On the Lifecycle policy tab, turn off Customize for this repository.

none can be set through the CLI and the API only.

Result

The save answers with what the policy would delete right now (wouldExpire) and a decision for every image. The next hourly run applies it, at most 1,000 images per repository a run. Each run that deletes anything writes an event to the repository's activity, with the first images and why.

If it is refused

  • 400 with the problems when the policy is neither a valid ews-lifecycle/v1 policy nor a valid AWS ECR policy (in the console, Save policy stays disabled and the form shows the problems).
  • 403 without ecr:PutLifecyclePolicy (ecr:DeleteLifecyclePolicy for delete).
Did this page help you?