# S3BucketOriginWithOAIProps

Struct · Stable

Properties for configuring a S3 origin with OAI.

Extends: [S3BucketOriginBaseProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront_origins.S3BucketOriginBaseProps.html)
Used as argument in: [S3BucketOrigin.withOriginAccessIdentity](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront_origins.S3BucketOrigin.html#withoriginaccessidentity)

- Source: [`aws-cloudfront-origins/lib/s3-bucket-origin.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-cloudfront-origins/lib/s3-bucket-origin.ts#L57)
- Type last changed: v2.234.0 · 8 Jan 2026

## Example

TypeScript:

```ts
const myBucket = new s3.Bucket(this, 'myBucket');
const myOai = new cloudfront.OriginAccessIdentity(this, 'myOAI', {
  comment: 'My custom OAI'
});
const s3Origin = origins.S3BucketOrigin.withOriginAccessIdentity(myBucket, {
  originAccessIdentity: myOai
});
new cloudfront.Distribution(this, 'myDist', {
  defaultBehavior: {
    origin: s3Origin
  },
});
```

Python:

```python
my_bucket = s3.Bucket(self, "myBucket")
my_oai = cloudfront.OriginAccessIdentity(self, "myOAI",
    comment="My custom OAI"
)
s3_origin = origins.S3BucketOrigin.with_origin_access_identity(my_bucket,
    origin_access_identity=my_oai
)
cloudfront.Distribution(self, "myDist",
    default_behavior=cloudfront.BehaviorOptions(
        origin=s3_origin
    )
)
```

Java:

```java
Bucket myBucket = new Bucket(this, "myBucket");
OriginAccessIdentity myOai = OriginAccessIdentity.Builder.create(this, "myOAI")
        .comment("My custom OAI")
        .build();
IOrigin s3Origin = S3BucketOrigin.withOriginAccessIdentity(myBucket, S3BucketOriginWithOAIProps.builder()
        .originAccessIdentity(myOai)
        .build());
Distribution.Builder.create(this, "myDist")
        .defaultBehavior(BehaviorOptions.builder()
                .origin(s3Origin)
                .build())
        .build();
```

C#:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var myBucket = new Bucket(this, "myBucket");
var myOai = new OriginAccessIdentity(this, "myOAI", new OriginAccessIdentityProps {
    Comment = "My custom OAI"
});
var s3Origin = S3BucketOrigin.WithOriginAccessIdentity(myBucket, new S3BucketOriginWithOAIProps {
    OriginAccessIdentity = myOai
});
new Distribution(this, "myDist", new DistributionProps {
    DefaultBehavior = new BehaviorOptions {
        Origin = s3Origin
    }
});
```

Go:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
myBucket := s3.NewBucket(this, jsii.String("myBucket"))
myOai := cloudfront.NewOriginAccessIdentity(this, jsii.String("myOAI"), &OriginAccessIdentityProps{
	Comment: jsii.String("My custom OAI"),
})
s3Origin := origins.S3BucketOrigin_WithOriginAccessIdentity(myBucket, &S3BucketOriginWithOAIProps{
	OriginAccessIdentity: myOai,
})
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: s3Origin,
	},
})
```

## Properties

- `connectionAttempts`: number = 3 — The number of times that CloudFront attempts to connect to the origin;

  valid values are 1, 2, or 3 attempts.

- `connectionTimeout`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.seconds(10) — The number of seconds that CloudFront waits when trying to establish a connection to the origin.

  Valid values are 1-10 seconds, inclusive.

- `customHeaders`: { [key: string]: string } = {} — A list of HTTP header names and values that CloudFront adds to requests it sends to the origin.

- `originAccessControlId`: string — The unique identifier of an origin access control for this origin.

  **Default:** no origin access control

- `originAccessIdentity`: any — An optional Origin Access Identity.

  **Default:** an Origin Access Identity will be created.

- `originId`: string — A unique identifier for the origin.

  **Default:** an originid will be generated for you

  This value must be unique within the distribution.

- `originPath`: string = '/' — An optional path that CloudFront appends to the origin domain name when CloudFront requests content from the origin.

  Must begin, but not end, with '/' (e.g., '/production/images').

- `originShieldEnabled`: boolean = true — Origin Shield is enabled by setting originShieldRegion to a valid region, after this to disable Origin Shield again you must set this flag to false.

- `originShieldRegion`: string — When you enable Origin Shield in the AWS Region that has the lowest latency to your origin, you can get better network performance.

  **Default:** origin shield not enabled

- `responseCompletionTimeout`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — The time that a request from CloudFront to the origin can stay open and wait for a response.

  **Default:** undefined - AWS CloudFront default is not enforcing a maximum value

  If the complete response isn't received from the origin by this time, CloudFront ends the connection.

  Valid values are 1-3600 seconds, inclusive.
