AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

LogRetention

Creates a custom resource to control the retention policy of a CloudWatch Logs log group. The log group is created if it doesn't already exist. The policy is removed when `retentionDays` is `undefined` or equal to `Infinity`. Log group can be created in the region that is different from stack region by specifying `logGroupRegion`

Import

import { LogRetention } from 'aws-cdk-lib/aws-logs';

Or use the module namespace:

import * as logs from 'aws-cdk-lib/aws-logs';
// logs.LogRetention

Properties

Configuration passed to the constructor as LogRetentionProps.

logGroupNameRequired
string

The log group name.

retentionRequired
RetentionDays

The number of days log events are kept in CloudWatch Logs.

logGroupRegionOptional
string

The region where the log group should be created.

Default: - same region as the stack

logRetentionRetryOptionsOptional
LogRetentionRetryOptions

Retry options for all AWS API calls.

Default: - AWS SDK default retry options

removalPolicyOptional
RemovalPolicy

The removalPolicy for the log group when the stack is deleted.

Default: RemovalPolicy.RETAIN

roleOptional
IRole

The IAM role for the Lambda function associated with the custom resource.

Default: - A new role is created

Learn AWS the Practical Way

Our bi-weekly newsletter teaches hands-on AWS fundamentals. No certification fluff - just practical knowledge.

Subscribe to Newsletter