S3BucketOrigin Class
A S3 Bucket Origin.
| Source | aws-cloudfront-origins/lib/s3-bucket-origin.ts |
|---|---|
| Type last changed |
Example
ts
import * as kms from 'aws-cdk-lib/aws-kms';
const myKmsKey = new kms.Key(this, 'myKMSKey');
const myBucket = new s3.Bucket(this, 'mySSEKMSEncryptedBucket', {
encryption: s3.BucketEncryption.KMS,
encryptionKey: myKmsKey,
objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_ENFORCED,
});
new cloudfront.Distribution(this, 'myDist', {
defaultBehavior: {
origin: origins.S3BucketOrigin.withOriginAccessControl(myBucket) // Automatically grants Distribution access to `myKmsKey`
},
});
python
import aws_cdk.aws_kms as kms
my_kms_key = kms.Key(self, "myKMSKey")
my_bucket = s3.Bucket(self, "mySSEKMSEncryptedBucket",
encryption=s3.BucketEncryption.KMS,
encryption_key=my_kms_key,
object_ownership=s3.ObjectOwnership.BUCKET_OWNER_ENFORCED
)
cloudfront.Distribution(self, "myDist",
default_behavior=cloudfront.BehaviorOptions(
origin=origins.S3BucketOrigin.with_origin_access_control(my_bucket)
)
)
java
import software.amazon.awscdk.services.kms.*;
Key myKmsKey = new Key(this, "myKMSKey");
Bucket myBucket = Bucket.Builder.create(this, "mySSEKMSEncryptedBucket")
.encryption(BucketEncryption.KMS)
.encryptionKey(myKmsKey)
.objectOwnership(ObjectOwnership.BUCKET_OWNER_ENFORCED)
.build();
Distribution.Builder.create(this, "myDist")
.defaultBehavior(BehaviorOptions.builder()
.origin(S3BucketOrigin.withOriginAccessControl(myBucket))
.build())
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.KMS;
var myKmsKey = new Key(this, "myKMSKey");
var myBucket = new Bucket(this, "mySSEKMSEncryptedBucket", new BucketProps {
Encryption = BucketEncryption.KMS,
EncryptionKey = myKmsKey,
ObjectOwnership = ObjectOwnership.BUCKET_OWNER_ENFORCED
});
new Distribution(this, "myDist", new DistributionProps {
DefaultBehavior = new BehaviorOptions {
Origin = S3BucketOrigin.WithOriginAccessControl(myBucket)
}
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import kms "github.com/aws/aws-cdk-go/awscdk"
myKmsKey := kms.NewKey(this, jsii.String("myKMSKey"))
myBucket := s3.NewBucket(this, jsii.String("mySSEKMSEncryptedBucket"), &BucketProps{
Encryption: s3.BucketEncryption_KMS,
EncryptionKey: myKmsKey,
ObjectOwnership: s3.ObjectOwnership_BUCKET_OWNER_ENFORCED,
})
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
DefaultBehavior: &BehaviorOptions{
Origin: origins.S3BucketOrigin_WithOriginAccessControl(myBucket),
},
})
Initializer
ts
new S3BucketOrigin(bucket: IBucket, props?: S3BucketOriginBaseProps)
python
S3BucketOrigin(bucket: IBucket, props: typing.Optional[S3BucketOriginBaseProps] = None)
java
new S3BucketOrigin(IBucket bucket, S3BucketOriginBaseProps props)
csharp
new S3BucketOrigin(IBucket bucket, S3BucketOriginBaseProps? props = null)
go
NewS3BucketOrigin(Bucket IBucket, Props S3BucketOriginBaseProps)
Methods
bind(scope: Construct, options: OriginBindOptions): OriginBindConfigdef bind(self, scope: Construct, options: OriginBindOptions) -> OriginBindConfigpublic OriginBindConfig bind(Construct scope, OriginBindOptions options)public OriginBindConfig Bind(Construct scope, OriginBindOptions options)func Bind(Scope Construct, Options OriginBindOptions) OriginBindConfig #Binds the origin to the associated Distribution.
Can be used to grant permissions, create dependent resources, etc.
withBucketDefaults(bucket: IBucket, props?: OriginProps): IOrigin@staticmethod def with_bucket_defaults(bucket: IBucket, props: typing.Optional[OriginProps] = None) -> IOriginpublic static IOrigin withBucketDefaults(IBucket bucket, OriginProps props)public static IOrigin WithBucketDefaults(IBucket bucket, OriginProps? props = null)func WithBucketDefaults(Bucket IBucket, Props OriginProps) IOrigin static #Create a S3 Origin with default S3 bucket settings (no origin access control).
withOriginAccessControl(bucket: IBucket, props?: S3BucketOriginWithOACProps): IOrigin@staticmethod def with_origin_access_control(bucket: IBucket, props: typing.Optional[S3BucketOriginWithOACProps] = None) -> IOriginpublic static IOrigin withOriginAccessControl(IBucket bucket, S3BucketOriginWithOACProps props)public static IOrigin WithOriginAccessControl(IBucket bucket, S3BucketOriginWithOACProps? props = null)func WithOriginAccessControl(Bucket IBucket, Props S3BucketOriginWithOACProps) IOrigin static #Create a S3 Origin with Origin Access Control (OAC) configured.
withOriginAccessIdentity(bucket: IBucket, props?: S3BucketOriginWithOAIProps): IOrigin@staticmethod def with_origin_access_identity(bucket: IBucket, props: typing.Optional[S3BucketOriginWithOAIProps] = None) -> IOriginpublic static IOrigin withOriginAccessIdentity(IBucket bucket, S3BucketOriginWithOAIProps props)public static IOrigin WithOriginAccessIdentity(IBucket bucket, S3BucketOriginWithOAIProps? props = null)func WithOriginAccessIdentity(Bucket IBucket, Props S3BucketOriginWithOAIProps) IOrigin static #Create a S3 Origin with Origin Access Identity (OAI) configured OAI is a legacy feature and we **strongly** recommend you to use OAC via `withOriginAccessControl()` unless it is not supported in your required region (e.g. China regions).