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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ