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 年前3849 查看次数
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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则