class LogRetention (construct)
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.Logs.LogRetention |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awslogs#LogRetention |
Java | software.amazon.awscdk.services.logs.LogRetention |
Python | aws_cdk.aws_logs.LogRetention |
TypeScript (source) | aws-cdk-lib » aws_logs » LogRetention |
Implements
IConstruct, IDependable
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
Example
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
import { aws_logs as logs } from 'aws-cdk-lib';
declare const role: iam.Role;
const logRetention = new logs.LogRetention(this, 'MyLogRetention', {
logGroupName: 'logGroupName',
retention: logs.RetentionDays.ONE_DAY,
// the properties below are optional
logGroupRegion: 'logGroupRegion',
logRetentionRetryOptions: {
base: cdk.Duration.minutes(30),
maxRetries: 123,
},
removalPolicy: cdk.RemovalPolicy.DESTROY,
role: role,
});
Initializer
new LogRetention(scope: Construct, id: string, props: LogRetentionProps)
Parameters
- scope
Construct - id
string - props
LogRetention Props
Construct Props
| Name | Type | Description |
|---|---|---|
| log | string | The log group name. |
| retention | Retention | The number of days log events are kept in CloudWatch Logs. |
| log | string | The region where the log group should be created. |
| log | Log | Retry options for all AWS API calls. |
| removal | Removal | The removalPolicy for the log group when the stack is deleted. |
| role? | IRole | The IAM role for the Lambda function associated with the custom resource. |
logGroupName
Type:
string
The log group name.
retention
Type:
Retention
The number of days log events are kept in CloudWatch Logs.
logGroupRegion?
Type:
string
(optional, default: same region as the stack)
The region where the log group should be created.
logRetentionRetryOptions?
Type:
Log
(optional, default: AWS SDK default retry options)
Retry options for all AWS API calls.
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.RETAIN)
The removalPolicy for the log group when the stack is deleted.
role?
Type:
IRole
(optional, default: A new role is created)
The IAM role for the Lambda function associated with the custom resource.
Properties
| Name | Type | Description |
|---|---|---|
| log | string | The ARN of the LogGroup. |
| node | Node | The tree node. |
| static PROPERTY_INJECTION_ID | string | Uniquely identifies this class. |
logGroupArn
Type:
string
The ARN of the LogGroup.
node
Type:
Node
The tree node.
static PROPERTY_INJECTION_ID
Type:
string
Uniquely identifies this class.
Methods
| Name | Description |
|---|---|
| to | Returns a string representation of this construct. |
| with(...mixins) | Applies one or more mixins to this construct. |
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
with(...mixins)
public with(...mixins: IMixin[]): IConstruct
Parameters
- mixins
IMixin— The mixins to apply.
Returns
Applies one or more mixins to this construct.
Mixins are applied in order. The list of constructs is captured at the
start of the call, so constructs added by a mixin will not be visited.
Use multiple with() calls if subsequent mixins should apply to added
constructs.

.NET
Go
Java
Python
TypeScript (