Review CloudWatch log retention

Set CloudWatch log retention to meet operational and regulatory needs, avoiding both lost evidence and unnecessary storage.

Description

CloudWatch logs do not expire if you omit retention_in_days in Terraform or set it to 0. A short retention period can delete logs you still need for an investigation.

Choose a retention period that meets your operational and regulatory requirements. For long-term storage, document why the logs are needed, who can access them, and how you will manage costs.

Potential impact

  • Unnecessary retention can cause storage costs to keep growing.
  • Inconsistent retention across resources can make operational policy harder to apply.
  • Required logs can be deleted too early, or sensitive records can remain longer than necessary.

Remediation

  • Specify retention_in_days according to investigation and audit requirements, and apply the same policy to new log groups.
  • Before shortening retention, assess the effect on existing logs and preserve records that must be kept separately. Deletion of expired logs can take time.
  • Regularly review log access, storage cost and changes to retention requirements.

Examples

Thirty days is illustrative, not a universal requirement for every service or regulation.

Before

hcl
resource "aws_cloudwatch_log_group" "app" {
  name = "/aws/app/service"
}

After

hcl
resource "aws_cloudwatch_log_group" "app" {
  name              = "/aws/app/service"
  retention_in_days = 30
}

Explanation:

  • Before: Retention is omitted, so logs do not expire.
  • After: Log retention is set to 30 days. Also review existing records that will become eligible for expiration because of this change.

References