Search code examples
amazon-cloudfront

accessing path through cloudfront gives access denied


I got a website hosted in cloudfront using an origin id to acess angualr app data in my non-public s3 bucket. things work fine except that users cannot access paths like www.exmaple.com/path, users do get access denied. They always have to start at root. I need to enable that access but am struggeling. I found that post, but frank, I dont understand it. AWS CloudFront redirect to path

I found a workaround by making bucket public and use static website hosting, problem is only that users can bybass cloudfront and go to bucket right away.

anybody got a hint on how to enable paths?


Solution

  • I found some post explaining it.

    1. U need to use the static website hosting enpoint an make it public

    2. In cloudfront you set a header named Referer and give some random secret as value.

    3. You put a bucket policy like this:

      { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "", "Action": [ "s3:GetObject", "s3:GetObjectVersion" ], "Resource": "arn:aws:s3:::yours3bucket/", "Condition": { "StringLike": { "aws:Referer": "yoursecretvalue" } } }, { "Effect": "Deny", "Principal": "", "Action": [ "s3:GetObject", "s3:GetObjectVersion" ], "Resource": "arn:aws:s3:::yours3bucket/", "Condition": { "StringNotLike": { "aws:Referer": "yoursecretvalue" } } } ] }