# Providing lifecycle rules for ECR repositories

**URL:** <https://forum.serverless.com/t/providing-lifecycle-rules-for-ecr-repositories/19425>\
**Category:** Serverless Framework\
**Created:** [August 23, 2023, 9:12am UTC](https://forum.serverless.com/t/providing-lifecycle-rules-for-ecr-repositories/19425 "2023-08-23T09:12:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tibbe](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tibbe/32/6732_2.png) [@tibbe](https://forum.serverless.com/u/tibbe)\
**Post date:** [August 23, 2023, 9:12am UTC](https://forum.serverless.com/t/providing-lifecycle-rules-for-ecr-repositories/19425/1 "2023-08-23T09:12:59Z")

</div>

Our costs for ECR storage are starting to go up and I noticed that when using the Docker image feature of Serverless Framework there seems to be no lifecycle management policy. Is it possible to set one? Could I write some custom CloudFormation XML that refers to the repository created by the Serverless Framework?

---

<div class="post-metadata">

**Author:** ![georgebv](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/georgebv/32/7696_2.png) [@georgebv](https://forum.serverless.com/u/georgebv)\
**Post date:** [October 27, 2023, 12:20am UTC](https://forum.serverless.com/t/providing-lifecycle-rules-for-ecr-repositories/19425/2 "2023-10-27T00:20:41Z")

</div>

Encountering the same issue as well. This is a much needed feature indeed. For now, my solution is to run a python script after the serverless deploy command:

```auto
boto3.client("ecr").put_lifecycle_policy(
    repositoryName="-".join(
        [
            "serverless",
            "<your stack name>",
        ]
    ),
    lifecyclePolicyText=json.dumps(
        {
            "rules": [
                {
                    "rulePriority": 1,
                    "description": "Expire untagged images older than 1 day",
                    "selection": {
                        "tagStatus": "untagged",
                        "countType": "sinceImagePushed",
                        "countUnit": "days",
                        "countNumber": 1,
                    },
                    "action": {
                        "type": "expire",
                    },
                },
            ],
        },
    ),
)

```

---

<div class="post-metadata">

**Author:** ![mmierzwa](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mmierzwa/32/8528_2.png) [@mmierzwa](https://forum.serverless.com/u/mmierzwa)\
**Post date:** [May 4, 2026, 1:18pm UTC](https://forum.serverless.com/t/providing-lifecycle-rules-for-ecr-repositories/19425/3 "2026-05-04T13:18:38Z")

</div>

Do you know if anything has changed sice you posted your original question?
