use two Cloudfront Behaviors in CDK v2
I am about to build a Cloudfront Distribution using CDK v2 using typescript. I have a hard time understanding how to add it. I want default to go to some s3 bucketA and a path /image/ shall go to bucketB.
const distri = new cloudfront.Distribution(this, 'myDist', {
defaultBehavior: { origin: new origins.S3Origin(bucketA)},
additionalBehaviors: ???? // path image should got to origin bucketB
});
Anybody got a helping hand?
You can try something like this-
const distri = new cloudfront.Distribution(this, 'myDist', { defaultBehavior: { origin: new origins.S3Origin(bucketA) }, additionalBehaviors: { '/image/' :{ origin: new origins.S3Origin(bucketB) } } // path image should got to origin bucketB });
more samples on Distribution API here-
https://docs.aws.amazon.com/cdk/api/v1/docs/aws-cloudfront-readme.html#multiple-behaviors--origins
hope this helps.
That works! I was reading the { [string]: BehaviorOptions }
from the docs as some string list what was causing my confusion
Relevant questions
use two Cloudfront Behaviors in CDK v2
Accepted Answerasked 3 months agoDeploying greengrass v2 public components using CDK (e.g. ShadowManager)?
asked a month agoAccess denied when trying to GET objects uploaded to s3 bucket via aws sdk using cloudfront
asked 6 months agoHow to add domain alias to existing CloudFront distribution using CDK
Accepted Answerasked 6 months agoOAI or not OAI for serving a static website in S3 using CloudFront
asked a month agoWatching TypeScript CDK Builds
asked 2 months agoCloudfront with a Lambda@Edge pointing to a private S3
asked 2 years agoCDK: put aws apigateway events on to default bus in EventBridge
asked 2 months agoHow to setup CloudFront default root object?
Accepted Answerasked 2 days agoCDK - how to set OpenSearch/Elasticsearch as the destination of a Kinesis Firehose?
asked 2 months ago