16

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.

Leon
  • 1,851
  • 3
  • 21
  • 44

3 Answers3

8

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

Kush Vyas
  • 5,813
  • 2
  • 26
  • 36
  • 2
    After some playing around with Cloudfront, I find the performance of S3 + Cloudfront to be great :) – Leon Jun 02 '18 at 08:16
  • 1
    Sometime after this post was written I have found myself going back to EC2 because greater control over URL re-writing could be achieved without having to learn Lambda. However, S3 + Cloudfront is considerably cheaper (free) than paying for another EC2 server. – Leon Nov 08 '19 at 11:09
7

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

1

Updated: 13 Jan 2020

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

https://aws.amazon.com/getting-started/projects/build-serverless-web-app-lambda-apigateway-s3-dynamodb-cognito/module-1/

Chuong Tran
  • 3,131
  • 17
  • 25