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?

2 Risposte
1
Risposta accettata

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
con risposta 2 anni fa
1

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

AWS
Marco
con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande