Why is AWS S3 returning a 404 when I can see the file in the S3 Management Console? - amazon-web-services

I the title pretty much sums up my problem. I have uploaded the files using the web interface, can launch the index.html, but the PDF in an assets folder returns a 404.
The server responds with:
404 Not Found
Code: NoSuchKey
Message: The specified key does not exist.
Key: assets/PDF/piano0817.pdf
RequestId: 02770C292FC4DBFA
HostId: zSn07EPw7JngHLCdcveteFDJNKATslKDCSKkJSAhsFsbW+gfeVQwvFMu3WMcY513iwt32F/OG1c=```
I have waited the prescribed hour but S3 will still not serve my PDF. What am I doing wrong?

Go to S3 bucket properties -> Static web hosting and add index.html as Error document.
It considers everything as directory once you append something to host URL. Now after adding index.html as Error document, when it doesn't find the required path as a folder, it will go to index.html and redirect your request.

Related

Amazon S3 SOAP in URL returns empty 200

We have a static site hosted on Amazon S3 with a CloudFront CDN. There is a 404 error page in CloudFront that redirects to the site to be handled on the client side (react routing).
All 404 pages work correctly but if I have "/soap" in the URL, it returns a 200 and a blank response. I believe s3 is returning a 200 instead of a 404 when /soap is in the URL.
How would I prevent s3 from intercepting /soap requests and return a 404?
This problem occurs when you have an Improper directory control. Instead of directly copying build outputs in s3 bucket, first create a folder with random name and paste the build output in that random folder.
Now you have to provide Origin path in your Cloud Front distributions. For setting origin path, you need to open your Cloud Front distribution console and select Origins tab and then select your Origin then click on edit, you can now find Origin path section under settings. Now you have to provide your random folder name there with '/'. (For example: /Random Folder). Now you can check this with "/soap" in the URL it will redirect to your Error Page.
For setting Origin Path you can refer the following link:
Setting Origin Path in AWS Cloud Front Distribution

static website on s3 gives 404 on refresh for non home page: no such keys error

On clicking/refresh following site https://rrc6k2ykxxxxx.cloudfront.net/example-1
this error comes for all non home page url
I have reactjs App on s3 bucket which is served through cloudfront.
Error:
NoSuchKey
The specified key does not exist.
Key: example-1
what would be best way to redirect refresh on non home pages back to home page? thanks
Assuming this is a single page app (SPA) since this is react - in other words, there is no file in your s3 bucket example-1/index.html?
For single-page apps, whatever is delivering the static contents needs to return the root index.html file for all unmatched paths. In CloudFront, you can click on the distribution, then click on "Error pages", click "Create a custom error response", select 404 for the HTTP error code, select "create a custom error response" and put /index.html in the response page path with a 200 for the response code. You will want to repeat this for a 403 error code.
Just set the Error Page to index.html it will solve the problem. path => Go to aws s3 then in buckets select properties tab and go to Static website hosting
Static website hosting

AWS S3 / Cloudfront deployment - certain paths aren't updating on static website

I'm fairly new to AWS and web dev - I have a simple static website at https://iveyfintechclub.ca
I recently refactored the code and made some changes to the project organization. I basically wiped the S3 bucket and reuploaded all new files and folders.
On CloudFront, I have object caching set to use origin cache headers:
my CloudFront distribution behavior config
I also did an invalidation with /*.
On S3, I've set the metadata Cache-Control to max-age=0 for all files.
Two problems are still eluding me:
The old bucket had a blank index.html which redirected to a
nested HTML file. The new bucket has index.html as the landing page.
When I attempt to visit the root URL, I get a 404 error as it still
attempts to reach the old nested HTML path. This doesn't happen in incognito mode (browser cache issue).
2. On the new landing page, I have a script file which is getting a 404
error as its looking for the file on its old path. Inspecting the HTML shows that the new path is in the client. This is happening in incognito mode too. All other resources are loading properly with
new paths, just this one is failing.
I'm wondering if I just have to wait longer or if I'm still missing a configuration.

Subdirectory pages not found static site hosted on Google Cloud Storage Bucket

I'm setting up a static site on a Google Cloud Storage Bucket with Loadbalancer. The site gets generated with Gridsome and then the dist folder gets saved in the bucket.
I have set the index and error with gsutil like in the [documentation]: https://cloud.google.com/storage/docs/gsutil/commands/web
Now I am facing a problem with how every url for accessing subdirectories gets redirected to dir/index.html. This is desired behavior, the dir/index.html page even exists in the bucket. But I still get a 404 - not found.
If I do a curl to the url subdir/index.html I get the HTML
I do not know exactly how you are testing your subfolder but I think this link can help you with your issue Error 404 when loading subfolder on GCS. In addition, you maybe must to take a look here How subdirectories work.
Based on How subdirectories work on GCS, when browser request URL http://www.example.com/dir it will be redirect (301) to The object http://www.example.com/dir/index.html on content served.
My assumption is there is no route http://www.example.com/dir/index.html on Vue (vue-router). So it will be throw to Not Found 404 page.
The simple solution is try to change all subdirectories link from
http://www.example.com/dir, http://www.example.com/about etc, to
http://www.example.com/dir/, http://www.example.com/about/
It will not redirect to 404 page when you request subdirectories url or reload the browser. But we all know that it's not best practices.

AWS S3 NoSuchKey when trying to open subfolder

I added subfolder (for example mysubfolder) to my site (for example https://www.example.com), and when I open this link (https://www.example.com/mysubfolder) on browser I get error:
404 Not Found
Code: NoSuchKey
Message: The specified key does not exist.
Your request is probably to the wrong/misspelled path for your S3 static site. Make sure that mysubfolder exists in your bucket root path.