use two Cloudfront Behaviors in CDK v2

0

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?

AWS
Marco
질문됨 2년 전3850회 조회
2개 답변
1
수락된 답변

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.

AWS
답변함 2년 전
1

That works! I was reading the { [string]: BehaviorOptions }from the docs as some string list what was causing my confusion

AWS
Marco
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠