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?
1 Like
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:
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",
},
},
],
},
),
)