EC2 or S3 to host AngularJS app?

All we need is an easy explanation of the problem, so here it is.

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.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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.


Method 2

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:

Method 3

Updated: 13 Jan 2020

Another way, we can host an Angular app with S3 and enable Website hosting

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply