# ObjectLockRetention

The default retention settings for an S3 Object Lock configuration.

Obtainable from: ObjectLockRetention.compliance, ObjectLockRetention.governance

- Source: [`aws-s3/lib/bucket.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-s3/lib/bucket.ts#L3952)
- Type last changed: v2.64.0 · 9 Feb 2023

## Example

TypeScript:

```ts
// 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)),
});
```

Python:

```python
# Configure for governance mode with a duration of 7 years
s3.Bucket(self, "Bucket1",
    object_lock_default_retention=s3.ObjectLockRetention.governance(Duration.days(7 * 365))
)

# Configure for compliance mode with a duration of 1 year
s3.Bucket(self, "Bucket2",
    object_lock_default_retention=s3.ObjectLockRetention.compliance(Duration.days(365))
)
```

Java:

```java
// Configure for governance mode with a duration of 7 years
// Configure for governance mode with a duration of 7 years
Bucket.Builder.create(this, "Bucket1")
        .objectLockDefaultRetention(ObjectLockRetention.governance(Duration.days(7 * 365)))
        .build();

// Configure for compliance mode with a duration of 1 year
// Configure for compliance mode with a duration of 1 year
Bucket.Builder.create(this, "Bucket2")
        .objectLockDefaultRetention(ObjectLockRetention.compliance(Duration.days(365)))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// Configure for governance mode with a duration of 7 years
// Configure for governance mode with a duration of 7 years
new Bucket(this, "Bucket1", new BucketProps {
    ObjectLockDefaultRetention = ObjectLockRetention.Governance(Duration.Days(7 * 365))
});

// Configure for compliance mode with a duration of 1 year
// Configure for compliance mode with a duration of 1 year
new Bucket(this, "Bucket2", new BucketProps {
    ObjectLockDefaultRetention = ObjectLockRetention.Compliance(Duration.Days(365))
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Configure for governance mode with a duration of 7 years
// Configure for governance mode with a duration of 7 years
s3.NewBucket(this, jsii.String("Bucket1"), &BucketProps{
	ObjectLockDefaultRetention: s3.ObjectLockRetention_Governance(awscdk.Duration_Days(jsii.Number(7 * 365))),
})

// Configure for compliance mode with a duration of 1 year
// Configure for compliance mode with a duration of 1 year
s3.NewBucket(this, jsii.String("Bucket2"), &BucketProps{
	ObjectLockDefaultRetention: s3.ObjectLockRetention_Compliance(awscdk.Duration_*Days(jsii.Number(365))),
})
```

## Properties

- `duration`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — The default period for which objects should be retained.

- `mode`: [ObjectLockMode](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.ObjectLockMode.html) — The retention mode to use for the object lock configuration.

## Methods

- `compliance(duration: Duration): ObjectLockRetention // chainable` (static) — 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.

  **Parameters**

  - `duration` — the length of time for which objects should be retained.

  **Returns:** the ObjectLockRetention configuration

- `governance(duration: Duration): ObjectLockRetention // chainable` (static) — 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.

  **Parameters**

  - `duration` — the length of time for which objects should retained.

  **Returns:** the ObjectLockRetention configuration
