Is it possible to use amazon s3 to serve angular 2 app without using a dedicated server. If so how to proceed ?
Yes, you can deploy an application to AmazonS3 but you shouldn't serve it directly from Amazon S3: S3 is a Storing Service, not a Distribution Service. That's why you should create a CloudFront distribution for your S3 bucket.
Steps:
Build your app with npm run build --prod (be careful of including the --prod option!)
Create a CloudFront distribution for your Amazon S3 bucket and set your Default Root Object to index.html
If you use url rewrite and not hash strategy (your paths look like http://yourwebsite/login and not http://yourwebsite/#/login create a custom error response for your CloudFront distribution with the following:
HTTP Error Code: 404
Error Caching Minimum TTL (seconds): 0
You need also to be careful when you deploy your application to Invalidate index.html on CloudFront, otherwise an old version is cached and will be served to the client.
Please follow my guide for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With