# DefaultRetentionProperty

Struct · External

The container element for optionally specifying the default Object Lock retention settings for new objects placed in the specified bucket.

> - The `DefaultRetention` settings require both a mode and a period.
> - The `DefaultRetention` period can be either `Days` or `Years` but you must select one. You cannot specify `Days` and `Years` at the same time.

- Source: Generated at build time
- Type last changed: v2.272.0 · 30 Sep 2026

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_s3 as s3 } from 'aws-cdk-lib';
const defaultRetentionProperty: s3.CfnBucket.DefaultRetentionProperty = {
  days: 123,
  defaultEventHold: {
    days: 123,
    years: 123,
  },
  mode: 'mode',
  years: 123,
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_s3 as s3

default_retention_property = s3.CfnBucket.DefaultRetentionProperty(
    days=123,
    default_event_hold=s3.CfnBucket.DefaultEventHoldProperty(
        days=123,
        years=123
    ),
    mode="mode",
    years=123
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.s3.*;

DefaultRetentionProperty defaultRetentionProperty = DefaultRetentionProperty.builder()
        .days(123)
        .defaultEventHold(DefaultEventHoldProperty.builder()
                .days(123)
                .years(123)
                .build())
        .mode("mode")
        .years(123)
        .build();
```

C#:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.S3;

var defaultRetentionProperty = new DefaultRetentionProperty {
    Days = 123,
    DefaultEventHold = new DefaultEventHoldProperty {
        Days = 123,
        Years = 123
    },
    Mode = "mode",
    Years = 123
};
```

Go:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

defaultRetentionProperty := &DefaultRetentionProperty{
	Days: jsii.Number(123),
	DefaultEventHold: &DefaultEventHoldProperty{
		Days: jsii.Number(123),
		Years: jsii.Number(123),
	},
	Mode: jsii.String("mode"),
	Years: jsii.Number(123),
}
```

## Properties

- `days`: number — The number of days that you want to specify for the default retention period.

  If Object Lock is turned on, you must specify `Mode` and specify either `Days` or `Years` .

- `defaultEventHold`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnBucket.DefaultEventHoldProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.CfnBucket.DefaultEventHoldProperty.html) — The default Object Lock event hold duration that you want to apply to new objects placed in the specified bucket, unless an object's upload request specifies its own Object Lock settings.

  New object versions are placed under an event hold and remain protected while the hold is active. When the event hold is released, Amazon S3 retains the object version for this duration, measured from the time the hold is released.
    The ``DefaultEventHold`` duration can be specified in either ``Days`` or ``Years``, but you must select one. You can't specify ``Days`` and ``Years`` at the same time.

- `mode`: string — The default Object Lock retention mode you want to apply to new objects placed in the specified bucket.

  If Object Lock is turned on, you must specify `Mode` and specify either `Days` or `Years` .

- `years`: number — The number of years that you want to specify for the default retention period.

  If Object Lock is turned on, you must specify `Mode` and specify either `Days` or `Years` .
