Other Articles

CloudWatch Log Group – Configure Retention

Secure Configuration Checks > AWS

This check ensures that every Amazon CloudWatch log group has a retention period. By default, logs never expire, which grows storage cost and keeps data longer than needed.

Check Details

  • Resource: CloudWatch Log Group
  • Check: Configure log group retention (RetentionConfigured)
  • Risk: Logs pile up with no limit, raising cost and exposure

Remediation via AWS Console

  1. Log in to the AWS Management Console and open the Amazon CloudWatch console.

    Amazon CloudWatch Console
  2. In the left navigation pane, click Logs > Log Management. Find the log groups where the Retention column shows Never expire.

    CloudWatch log groups with Never expire retention
  3. Select one or more of these log groups.
  4. Click Actions > Edit retention setting(s). Choose a retention period and click Save.

    Edit retention setting

Remediation via AWS CLI

  1. Log in to the AWS Management Console and click the CloudShell icon (>_) in the top-right corner.

    AWS CloudShell
  2. List the log groups that never expire:

    aws logs describe-log-groups \
    --query 'logGroups[?!retentionInDays].logGroupName' \
    --output table
    

    The command covers one region. Add --region <region> to check another.

  3. Set a retention period on one log group:

    aws logs put-retention-policy \
    --log-group-name <log-group-name> \
    --retention-in-days <days>
    
  4. Or set the same period on every log group that never expires:

    DAYS=365
    
    for LG in $(aws logs describe-log-groups \
      --query 'logGroups[?!retentionInDays].logGroupName' \
      --output text); do
      aws logs put-retention-policy \
        --log-group-name "$LG" \
     --retention-in-days "$DAYS"
    done
    
    

    Use this only when one period suits all of these log groups.

  5. Verify the retention period:

    aws logs describe-log-groups \
    --log-group-name-prefix <log-group-name> \
    --query 'logGroups[*].[logGroupName,retentionInDays]' \
    --output table
    

Replace <log-group-name> with the log group name, for example /aws/lambda/my-function. Replace <days> with a valid period, for example 365.

Updated on 04 November, 2026