Creating a lifecycle policy - Amazon ECR

Creating a lifecycle policy

A lifecycle policy allows you to create a set of rules that expire unused repository images. The following procedure shows you how to create a lifecycle policy. You should expect that after creating a lifecycle policy, the affected images are expired within 24 hours.

To create a lifecycle policy using the console

  1. Open the Amazon ECR console at

  2. From the navigation bar, choose the Region that contains the repository for which to create a lifecycle policy.

  3. In the navigation pane, choose Repositories and select a repository.

  4. On the Repositories: repository_name page, in the navigation pane choose Lifecycle Policy.

  5. On the Repositories: repository_name: Lifecycle policy page, choose Create rule.

  6. Enter the following details for your lifecycle policy rule:

    1. For Rule priority, type a number for the rule priority.

    2. For Rule description, type a description for the lifecycle policy rule.

    3. For Image status, choose Tagged, Untagged, or Any.

    4. If you specified Tagged for Image status, then for Tag prefixes, you can optionally specify a list of image tags on which to take action with your lifecycle policy. If you specified Untagged, this field must be empty.

    5. For Match criteria, choose values for Since image pushed or Image count more than (if applicable).

  7. Choose Save.

To create a lifecycle policy using the AWS CLI

  1. Obtain the name of the repository for which to create the lifecycle policy.

    aws ecr describe-repositories
  2. Create a local file named policy.json with the contents of the lifecycle policy. For lifecycle policy examples, see Examples of lifecycle policies.

  3. Create a lifecycle policy by specifying the repository name and reference the lifecycle policy JSON file you created.

    aws ecr put-lifecycle-policy \ --repository-name repository-name \ --lifecycle-policy-text file://policy.json