From a9377a3ae1798640b701114d2f84a1500bc05d2e Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Fri, 18 Jul 2025 16:37:33 +0000 Subject: [PATCH] add auto delete policy --- .../lambda/lambda_example/docker/ecr.tf | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/deployment/lambda/lambda_example/docker/ecr.tf b/deployment/lambda/lambda_example/docker/ecr.tf index d9e2eab..4e29be7 100644 --- a/deployment/lambda/lambda_example/docker/ecr.tf +++ b/deployment/lambda/lambda_example/docker/ecr.tf @@ -23,3 +23,27 @@ resource "aws_ecr_repository_policy" "lambda_example_ecr_access" { }] }) } + +# ECR lifecycle policy to delete tagged images older than 14 days +resource "aws_ecr_lifecycle_policy" "extractor_loader_lifecycle" { + repository = aws_ecr_repository.lambda_example.name + + policy = jsonencode({ + rules = [ + { + rulePriority = 1 + description = "Delete tagged images older than 14 days" + selection = { + tagStatus = "tagged" + countType = "sinceImagePushed" + countUnit = "days" + countNumber = 14 + tagPrefixList = [""] # Matches all tagged images + } + action = { + type = "expire" + } + } + ] + }) +} \ No newline at end of file