Skip to main content
MEDIUMCloudWatchCost Optimization

CloudWatch Logs Retention Missing

cloudwatch-logs-retention-missing

What this rule checks

Detects CloudWatch Log Groups without an explicit retention period (logs retained indefinitely).

How to fix it

  1. 1Set RetentionInDays to control storage cost (30–90 days for ops, longer for compliance)
FlaggedRetentionDays.INFINITE leaves the log group with no RetentionInDays, so logs are retained indefinitely and storage cost grows forever. CDK Insights flags AWS::Logs::LogGroup resources with no explicit retention period.
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';

new LogGroup(this, 'AppLogs', {
  retention: RetentionDays.INFINITE,
});
FixedSetting retention to RetentionDays.ONE_MONTH emits an explicit RetentionInDays, bounding storage cost. The finding clears once a retention period is set.
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';

new LogGroup(this, 'AppLogs', {
  retention: RetentionDays.ONE_MONTH,
});

CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.

Affected resource types

AWS::Logs::LogGroup

AWS documentation

Read the AWS guidance

Intentional? Suppress this finding

Sometimes a flag is deliberate — a genuinely public endpoint, say. You can dismiss cloudwatch-logs-retention-missing and the reason is kept in the report, not silently hidden.

In .cdk-insights.json:

{
  "ignoreRules": [
    { "id": "cloudwatch-logs-retention-missing", "reason": "Why this is intentional" }
  ]
}

Or inline in your CDK code:

Validations.of(scope).acknowledge({
  id: 'cdk-insights::cloudwatch-logs-retention-missing',
  reason: 'Why this is intentional',
});

Use the rule ID cloudwatch-logs-retention-missing shown above — not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs →

Catch this in your stack

$ npx cdk-insights scan

CDK Insights runs this and 118+ other rules locally against your synthesised CDK app — free, no account, your code never leaves your machine.

More CloudWatch rules