Menu
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. You should expect that after creating a lifecycle policy, the affected images are expired within 24 hours.

To create a lifecycle policy using the AWS CLI

  1. Obtain the ID of 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>

To create a lifecycle policy using the console

  1. Open the Amazon ECS console at https://console.aws.amazon.com/ecs/.

  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 All repositories: repository_name page, choose Lifecycle Policy, Add.

  5. 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, 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).

  6. Choose Apply as lifecycle policy.

    Note

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