Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EC2 or S3 to host AngularJS app?

I want to launch a production version of an AngularJS application, and I find Amazon AWS to be an awesome hosting suite. As AngularJS is essentially static it could be hosted on S3 storage, or on an EC2 server with node.js backend.

Either of these solutions would suit my deployment method, so the question is, will I (in theory) get better performance from one or the other, and why? Is there anything wrong with hosting a professional website frontend on S3? Does anyone have any experience with both methods? The site involves streaming audio, video and potentially many many users.

Any advice appreciated.

like image 689
Leon Avatar asked Jan 10 '18 11:01

Leon


People also ask

Can angular app be hosted in S3?

In this post, we will learn how to create a basic angular application and host them in the AWS S3 service. Let's start with creating our angular project. First, we need to install the latest version of Angular CLI by running the following command.

What is the best server to deploy angular app?

Because these files are static, you can host them on any web server capable of serving files; such as Node. js , Java, . NET, or any backend such as Firebase, Google Cloud, or App Engine.

Can you host angular app on AWS?

AWS Amplify enables Angular developers to create high-quality applications on a flexible, scalable, and reliable serverless backend.


2 Answers

On reviewing your requirement if you are adamant about using S3 For Front end , I would like to suggest you use Cloudfront With S3 , the reason being:

S3 can't handle custom HTTP routes. Since "export" isn't a file S3 doesn't know what to do. In order to properly handle Angular routes you must use an actual HTTP Server like Nginx, Apache, IIS.

You can read these blog posts for more information :

How to host your Angular 2 application in AWS with S3

Using AWS CloudFront to serve an SPA hosted on S3

Now Moving to second option you mentioned using EC2 To host , I think using that option would give you more control over your environment and more flexibility on scaling too.

Thanks

like image 141
Kush Vyas Avatar answered Oct 03 '22 01:10

Kush Vyas


1) S3 Bucket + CloudFront (CDN) is really fast for static files serving. The Angular minified app is a group of static files which works best here. For the build of those minified files, I recommend using a CI/CD process or build them locally and just upload them to S3.

2) EC2 requires more work to setup, it consumes resources, it is not necessary for static files or Angular (unless you are using Angular Universal for dynamic content serving), and Node.js is not recommended for static files (Node.js get's blocked since it is single threaded so it is a best practice to keep static files away from it).

Here is a good article on the topic: https://www.quora.com/Should-I-use-AWS-EC2-to-host-an-Angular-web-app-or-AWS-S3

like image 45
Xavier Reyes Ochoa Avatar answered Oct 03 '22 01:10

Xavier Reyes Ochoa