LogRetention

class aws_cdk.aws_logs.LogRetention(scope, id, *, log_group_name, retention, log_group_region=None, log_retention_retry_options=None, removal_policy=None, role=None)

Bases: Construct

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

ExampleMetadata:

fixture=_generated

Example:

# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_iam as iam
from aws_cdk import aws_logs as logs

# role: iam.Role

log_retention = logs.LogRetention(self, "MyLogRetention",
    log_group_name="logGroupName",
    retention=logs.RetentionDays.ONE_DAY,

    # the properties below are optional
    log_group_region="logGroupRegion",
    log_retention_retry_options=logs.LogRetentionRetryOptions(
        base=cdk.Duration.minutes(30),
        max_retries=123
    ),
    removal_policy=cdk.RemovalPolicy.DESTROY,
    role=role
)
Parameters:
  • scope (Construct) –

  • id (str) –

  • log_group_name (str) – The log group name.

  • retention (RetentionDays) – The number of days log events are kept in CloudWatch Logs.

  • log_group_region (Optional[str]) – The region where the log group should be created. Default: - same region as the stack

  • log_retention_retry_options (Union[LogRetentionRetryOptions, Dict[str, Any], None]) – Retry options for all AWS API calls. Default: - AWS SDK default retry options

  • removal_policy (Optional[RemovalPolicy]) – The removalPolicy for the log group when the stack is deleted. Default: RemovalPolicy.RETAIN

  • role (Optional[IRole]) – The IAM role for the Lambda function associated with the custom resource. Default: - A new role is created

Methods

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

log_group_arn

The ARN of the LogGroup.

node

The tree node.

Static Methods

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.