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
preguntada hace 2 años3849 visualizaciones
2 Respuestas
1
Respuesta aceptada

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
respondido hace 2 años
1

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

AWS
Marco
respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas