aws-cdk-lib.aws_s3.ObjectLockRetention

class ObjectLockRetention

LanguageType name
.NETAmazon.CDK.AWS.S3.ObjectLockRetention
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awss3#ObjectLockRetention
Javasoftware.amazon.awscdk.services.s3.ObjectLockRetention
Pythonaws_cdk.aws_s3.ObjectLockRetention
TypeScript (source)aws-cdk-lib » aws_s3 » ObjectLockRetention

The default retention settings for an S3 Object Lock configuration.

See also: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-overview.html

Example

// Configure for governance mode with a duration of 7 years
new s3.Bucket(this, 'Bucket1', {
  objectLockDefaultRetention: s3.ObjectLockRetention.governance(Duration.days(7 * 365)),
});

// Configure for compliance mode with a duration of 1 year
new s3.Bucket(this, 'Bucket2', {
  objectLockDefaultRetention: s3.ObjectLockRetention.compliance(Duration.days(365)),
});

Properties

NameTypeDescription
durationDurationThe default period for which objects should be retained.
modeObjectLockModeThe retention mode to use for the object lock configuration.

duration

Type: Duration

The default period for which objects should be retained.


mode

Type: ObjectLockMode

The retention mode to use for the object lock configuration.

See also: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-overview.html#object-lock-retention-modes

Methods

NameDescription
static compliance(duration)Configure for Compliance retention for a specified duration.
static governance(duration)Configure for Governance retention for a specified duration.

static compliance(duration)

public static compliance(duration: Duration): ObjectLockRetention

Parameters

  • duration Duration — the length of time for which objects should be retained.

Returns

  • ObjectLockRetention

Configure for Compliance retention for a specified duration.

When an object is locked in compliance mode, its retention mode can't be changed, and its retention period can't be shortened. Compliance mode helps ensure that an object version can't be overwritten or deleted for the duration of the retention period.


static governance(duration)

public static governance(duration: Duration): ObjectLockRetention

Parameters

  • duration Duration — the length of time for which objects should retained.

Returns

  • ObjectLockRetention

Configure for Governance retention for a specified duration.

With governance mode, you protect objects against being deleted by most users, but you can still grant some users permission to alter the retention settings or delete the object if necessary. You can also use governance mode to test retention-period settings before creating a compliance-mode retention period.