Why is refreshing my Angular 6 project on S3/Cloudfront causing errors?

cloudfront angular routing
serve angular app on s3
s3 website cloudfront 403
angular s3 refresh
angular s3 403
give cloudfront access to s3
s3 static website cloudfront
cloudfront s3 webpack

I am having an issue with my Angular 6 project hosted on an S3 bucket with Cloudfront. Every time I refresh, the project seems to be lost and I am redirected to a page that says: What could be causing this? When I refresh on my local server, I am simply logged out and redirected to the login page. I thought this might be a problem with my S3 bucket settings, so I uploaded to the project that I knew was configured correctly (I had an Angular 5 project in there that didn't have the refresh problem). But, the same thing happened so it seems it is something within my project.

Could it be how I compile the files? I am using 'ng build'

Any help is appreciated! Thanks so much.

I just set index.html to Error document in the static website hosting and it work for me.

Angular on S3, refresh causes “AccessDenied” response, Why is refreshing my Angular 6 project on S3/Cloudfront causing errors? I am having an issue with my Angular 6 project hosted on an S3 bucket with Cloudfront. Here is how easy it is to deploy an Angular SPA (Single Page App) as a static website using S3, and with help of CloudFront for redirection.. Idea. So here is the basic schematic of what’s going

Within your s3 bucket, the built files need to have 'public' access

If you've just changed the permissions, it may take a few minutes before the changes are replicated across the s3 availability zones and cloudfront cache reads the new permissions

Deploy an Angular with S3 and CloudFront, Why is refreshing my Angular 6 project on S3/Cloudfront causing errors? - xml. An important thing to mention before continue: the only specific steps for Angular in this guide are the parts where we build the project and the automation part. Deploying and configuring the AWS S3, CloudFront and etc. are reusable and are the same for every static website deploy. So, if you are using React for example, this guide could be

It depends on how your AWS S3 project structure is.I am assuming you have given public access to the files (Access Control List) along with the correct Bucket Policy and you have put the build in the root directory.

Make sure that in the bucket properties(static site hosting) you have added index.html for the error document field.

Also make sure to add error pages in your cloudfront distribution, create 2 custom error responses for codes 403 & 404 which point to your index.html and return a response code of 200.

Edit: Here is a link to refer to https://hackernoon.com/hosting-static-react-websites-on-aws-s3-cloudfront-with-ssl-924e5c134455

Amplify Angular leads to 403 when page refresh · Issue #3606 · aws , You need to configure Cloudfront to handle the routing, so that all routes get redirected to refreshing the page results in 404 error- AWS - Angular 6 How do I redirect all requests to my static AWS S3 website to index.html so I can use  I migrated my project from Angular 5.2 to 6. My project runs now with no errors, however I don't think the development server is behaving correctly. Whenever I launch in debug, I no longer see that the development server is running in the Debug output. Secondly, whenever I save a file, the app does not refresh in the browser.

There are two possibilities:

(1) If your Angular on AWS S3 is client-side-rendered then every time you refresh your website your browser will send a request to AWS CloudFront to acquire the file from AWS S3.

eg. Reloading https://yourdomain.com/contact will actually sending a request to AWS S3 bucket > 'contact' directory > index.html, which is not existing because the page you're viewing is purely generated at client side.

Solution: CloudFront distribution > Error Pages > Create Custom Error Response > Create your custom responses for Error 400, 403, 404.

For example, an custom error response for Error 400:

HTTP Error Code: 400 Bad Request
Error Caching Minimum TTL: 300 
Customize Error Response: Yes
Response Page Path: /index.html
HTTP Response Code: 200 OK

(2) If your Angular is server-side-rendered, then you have to use your AWS S3 endpoint as the 'Origin Path Name' instead of the autocomplete from AWS dropdown list. For more details, you can refer to: Prerender Angular and Host It on AWS S3

Use S3 and CloudFront to host Static Single Page Apps (SPAs) with , Here is how to deploy an Angular SPA (Single Page App) as a static website using S3, and with help of CloudFront for redirection. If you Angular Project does use routing mechanism. Finally, now we need to configure 403 or 404 errors to redirect the traffic to index.html to do this. See responses (6)  Why your Angular App is not Working: 11 common Mistakes. Resolving problems of your angular application can be very challenging. When your angular app is not working and all it gives you are some cryptic red lines in a console. Especially when you are a beginner, these problems can turn the development process with angular into a real pain.

How can I make angular app child routes work with Amazon S3 , Amplify CloudFront Hosting Angular Amplify CLI Version 4.13.4 What A.. to host and review code, manage projects, and build software together. page refresh Amplify Angular leads to 403 when page refresh on Mar 6 Added hosting again to my Amplify App (S3 + CloudFront); Configured custom error  I upgraded my .NET Core 2.1 project to Angular 6 and everything seems to be working correctly except for hot-updates. Before updating it was possible to update the TypeScript and VS would re-compile and reload the browser, now that seems to be broken along with having to manually run ng build to recompile the scripts, VS doesn't seem to

How to handle 404 error in angular 6, Host a static website at S3; Redirect www.website.com to website.com a new CF domain) if you wanted a second project at app.mywebsite.com . FYI, I got 403s (instead of 404s) for my routes and needed to add a Cloudfront Error Page for CloudFront URL to the S3 URL which would cause a forbidden error because  Nevertheless, I did try to update my angular-cli and run ng init on my existing project. I notice now that I didn't follow the steps outlined on the angular-cli github page precisely. I skipped the npm install --save-dev angular-cli@latest , and I blew away all my node_modules instead of using the rm command they outline.

How to Build SEO Friendly Single Page Apps, However, when uploading to AWS S3 I can only access the main route as the child routes Is the problem apparent only after a refresh with URL set to the page with a This also causes confusion to newcomers and existing users of Angular, interconnected, my first thought was to create them all in one Angular project,  Step 5 - Updating from Angular v8.2.3 to The Latest Angular 9 Pre-Release Version. After updating our project to Angular 8, we will proceed to update it to the latest Angular 9 version. Head back to your terminal and run the ng update command again. You will get the following output: