Home > front end >  How to deploy a single web application(nodejs reactjs) on two EC2 server for load balancing and auto
How to deploy a single web application(nodejs reactjs) on two EC2 server for load balancing and auto

Time:10-27

My client is asking me to deploy web application (nodejs backend reactjs frontend) on two EC2 servers. Inorder to achieve good load balancing and autoscaling based on traffic, Note: client doesn't want to go for single server of high version

CodePudding user response:

Assuming the front-end is a SPA (browser-generated HTML), then host the React part on S3 CloudFront

Regarding deploying Node on EC2:

Use CloudFormation to setup the infrastructure (the EC2 machines, ASG, and Load Balancer)

Then use CodeDeploy to deploy / update the application

Here is a post on deploying Node.js using CodeDeploy: https://hub.packtpub.com/deploy-nodejs-apps-aws-code-deploy/

You might find it easier to use Elastic Beanstalk though

CodePudding user response:

There are multiple ways of achieving a satisfying architecture for this problem. If we are looking into using EC2 instances we can do the following:

Deploy your back-end into Target Group for an Auto Scaling Group and put an Application Load Balancer in front of it. Instances can automatically register to the load balancer, which can distribute traffic between them.

Deploy your static front-end application into an S3 bucket, if necessary, use a CloudFront distribution for caching and faster loads.

  • Related