Home > Back-end >  Not able to server multiple S3 buckets on a single Cloudfront Distribution
Not able to server multiple S3 buckets on a single Cloudfront Distribution

Time:01-03

Case:

I have a few S3 buckets that store my media files. I wanted to map all these s3 buckets to a single CF distribution. (their files should be accessed from different paths).

I have made a CF distribution and added 2 buckets. For the behaviour, the first bucket is on Default(*) and the second bucket is on path nature/*.

Issues:

  1. I am able to access the primary bucket (one with default behaviour) but not able to access the secondary bucket (with path nature/*). The error on accessing the secondary bucket is "Access Denied".

Additional details:

  1. Both my buckets are not available to global access and CF is accessing them from OAI.

References:

  1. enter image description here

    enter image description here

    CodePudding user response:

    Your files in the second bucket must start with a top level prefix nature/ or else the won't resolve. CF doesn't remove the path matched when routing, it is still there. If you can't move the objects in the second bucket into a nature/ prefix, then you need a CF Function to remove this part of the path from the object key before forwarding the request to the S3 origin.

  • Related