AWS S3 Bucket - Access Denied on Sub-Pages - amazon-web-services

So I have an AWS S3 Bucket hosting the files for a react application I've built. I use CodePipeline to build and compile the React app and store the files on an S3 bucket which is served through a CloudFront CDN.
Everything seems to be working fine when I access the url from the root https://website.com. When I click "login" on that page I get directed to the following route https://website.com/auth/login and it works awesome.
The Problem
If I try to access the page https://website.com/auth/login directly I get the following error:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>66CE67E2E5DA0B7B</RequestId>
<HostId>Spfhgnlygx05eugycEy5ew4e8oSn/ccNX21Iy/6qaAxI8glXljDjgKmUPvMzRd8+NktQsNietpg=</HostId>
</Error>
I set the default resource in the cloudfront CDN to the /index.html which is why the root domain works, but how do I get all there urls to point to /index.html so the app routes it properly?

I needed to set a rule for 403 Forbidden in my cloudfront configuration as posted here: Receive AccessDenied when trying to access a reload or refresh or one in new tab in angular 5

Related

Unable to access S3 objects via Cloudfront URL

I am unable to access S3 objects and Bucket via cloud front URL.
I have created CLOUDFRONT Distribution ( Web ) and setup origin path to media folder in my S3 bucket. ( /media)
CF url is pointing to bucket/media , but i am unable to access it from my web application as well as browser.
I am trying to access like below:
http://d1xdpXXXXX.cloudfront.net/media/images/Tiger.jpg
Tiger.jpg can be accessed via s3 url.
I also tried http://d1xdpXXXXX.cloudfront.net but i am getting below error:
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
<BucketName>d1xdpwiqgrffrd.cloudfront.net</BucketName>
<RequestId>484BBB2F7907172F</RequestId>
<HostId>+bLr4Qx+uawbq4YNIOuKGCQVDGQQQsifGnNt9J5Pn+r3mqbDiVYcpNZRUfnCyPnHxewfMVp3QYc=</HostId>
</Error>
Please help.
CF Distribution settings
Access denied error
You have already added the path in cloudfront origin.
So, you don't have to add that in cloudfront url you are using to download.
Just use
http://d1xdpXXXXX.cloudfront.net/images/Tiger.jpg
as /media is already part of the distribution.

AWS Cloudfront can't access S3 files deployed with CodeBuild

I'm working on getting a static website deployed with AWS Codebuild, hosted in an S3 bucket, and accessed via Cloudfront. Everything seems to work except from accessing from Cloudfront. From Cloudfront, I can access files that I manually upload, and using the bucket URL, I can access all the files. Looking through the individual file settings/permissions, they all look to be the same, regardless of whether they were manually uploaded, or deployed via Codebuild. I've tried invalidating the Cloudfront cache, and re-deployed via Codebuild several times.
Additional Information:
I provided the S3 bucket as an origin when setting up the Cloudfront distribution.
Accessing via Cloudfront gives the following error:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>0211CBE618946F</RequestId>
<HostId>
7sRZhaJS4x2W7Iaeo4y8KAjvsOJcNWh3PxCdgnhXPE22oyp1RxZhwpjrqbsWapsUSaqBK+jqE=
</HostId>
</Error>
What else should I check?
For some reason, adding a default root object fixed the issue.
FWIW, I initially changed the value to dist/index.html, which allowed me to access the deployed bucket contents via the Cloudfront URL, but required the index.html suffix. Once I changed it to index.html, everything worked fine.

Access Denied for index.html Amazon S3 static website

I've set up an example static website on Amazon S3 and I added a custom folder to it with file inside: custom-folder/index.html, but
I'm getting Access Denied error when trying to access url /custom-folder.
The index document is configured to be index.html, so S3 should serve index.html when I'm accessing /custom-folder url, but it doesn't work.
How can I fix this?
It seems you are using the wrong URL to access the bucket.
For example, when you enable to static website hosting feature in S3 (us-west-2 in this example), you are given a URL with the following format:
Endpoint : http://bucket-name.s3-website-us-west-2.amazonaws.com
You can see your endpoint by going to S3 > Click on your bucket > Bucket Properties > Static website hosting > should reveal your endpoint.
In case it helps anyone else, I was using a AWS Cloudfront Distribution on top of an S3 bucket.
The solution to the "Access Denied" issue for me was to perform the / to /index.html redirect in Cloudfront (rather than S3).
This is achieved by setting the "Default Root Object" to index.html on the AWS Cloudfront Distribution (and disabling "Static website hosting" entirely in S3).

Cloudfront url synchronized with s3 path

I was using s3 for for my static websites, we had three websites/paths in s3:
example.com
example.com/website1
example.com/website2
Website1 and Website2 were folders inside the bucket example.com as expected. But now we need https urls so we decided to go with aws cloudfront for the redirects. Cloudfront generated for example a url like this, https://123455678.cloudfront.net .
When I navigate to the url, it gets the example.com correctly, but when I try to put like https://123455678.cloudfront.net/website1 it seems like its not entering the /website1 path in the s3. So it gives me this error because it's not finding the index.html inside the /website1 path.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>C5259E1658595A69</RequestId>
<HostId>
B1HYQsr0Xv4M1avKlJ3G8t0rkVfCvbOoJadxm5z1BwapblBeERm3c6Ni+jZWxB8FlXEaF6bUAik=
</HostId>
</Error>
I guess I have to do something in the origins and behaviours of my cloudfront distribution, but I can't figure out what to do there...
I fixed my problem by changing the origin domain name in my cloudfront distribution to my s3 bucket endpoint, located in the properties of my bucket in Static Website Hosting area.
Saved, waited for cloudfront to use the updated changes and it worked. Also my Default Root Object is set to index.html .
Hope it helps someone =)

Amazon web service console- access denied for manifest file

I am new to Amazon web CloudFront console and S3 buckets. I am trying to get on-demand streaming work. When tried to view my uploaded video- ism file in the s3 bucket, I get the following XML response when entered following URL in a web browser:
http://mybucket.s3.amazonaws.com/videos/video_1/BigBuckBunny.ism/Manifest
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>C1EC48985EE12047</RequestId>
<HostId>
L7JtCmEHm9W3HUeZEV08GyoFBxiC4krHvoiQyPZrYxeOaIP8yhMJKP60+eIo5qTZcsDasW48Ck8=
</HostId>
</Error>
I am able to download this same ism file, using an url; http://mybucket.s3.amazonaws.com/videos/video_1/BigBuckBunny.ism. Then why only an issue with the manifest file which I will be accessing from my application?
From the following documentation given on Amazon, I have followed all 4 steps and I am now stuck at Step- 5.
http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/on-demand-streaming-smooth.html
What could I be missing? Any help is appreciated.
Amazon S3 does not know how to handle ism files, that's why /manifest doesn't work. What you need to do is configure your distribution with smooth streaming enabled, like the link you provided, and replace the s3 URL with cloudfront.
http://d124.cloudfront.net/videos/video_1/BigBuckBunny.ism/Manifest