Amazon ECR
User Guide (API Version 2015-09-21)

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 using the console. You should expect that after creating a lifecycle policy the affected images will be expired within 24 hours.

Setting up a lifecycle policy using the AWS CLI

  1. Obtain the ID for the repository for which to create the lifecycle policy:

    aws ecr describe-repositories
  2. Create a lifecycle policy:

    aws ecr put-lifecycle-policy [--registry-id <string>] --repository-name <string> --policy-text <string>

Setting up a lifecycle policy preview using the console

  1. Open the Amazon ECS console at

  2. From the navigation bar, choose the region that contains the repository on which to perform a lifecycle policy preview.

  3. In the navigation pane, choose Repositories.

  4. On the Repositories page, choose the repository on which to perform a lifecycle policy preview.

  5. On the All repositories: repository_name page, choose Lifecycle Policy, Add.

  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 either Tagged or Untagged.

    4. If you specified Tagged for Image Status, for Tag Prefix List, 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 Count Type, Count Number, and Count Unit (if applicable).

  7. Choose Apply as lifecycle policy.


    If you choose Dry Run, it creates a lifecycle policy preview.