Deploying react web application on AWS - node.js

I am looking to deploy my nodejs React web application on AWS. Currently I deployed my application on Microsoft's Azure and there is was pretty simple. I just had to add an App Service and give my git repository as the source to it. That took care of hosting my application. I am not getting a way like to do it on AWS. I am looking for something like that. How should I do it in AWS?

You can use AWS Elastic Beanstalk for this. Elastic Beanstalk is the PaaS offering which is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS. It is similar to Microsoft Azure App services.
You can simply upload your code and Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, auto-scaling to application health monitoring. At the same time, you retain full control over the AWS resources powering your application and can access the underlying resources at any time.
You can go through the tutorial for deploying your node.js app here- Deploying an Express Application to Elastic Beanstalk

One of the easy ways to do this in a Serverless manner is to use the new AWS Mobile CLI:
npm install -g awsmobile-cli
Then initialize and publish:
cd ./myproj
awsmobile init #answer some questions
awsmobile publish
This will setup an S3 bucket with CloudFront configured as your CDN to host your web assets. Your NodeJS app can be hosted in a Lambda function which is protected by API Gateway. A good way to configure the connection and authorzation from the client is to use AWS Amplify in your React application:
npm install aws-amplify --save
npm install aws-amplify-react --save
Then after doing an Amplify.configure(your_config_object you can connect to API gateway which calls your Lambda:
let apiName = 'MyApiName';
let path = '/path';
let myInit = { // OPTIONAL
headers: {} // OPTIONAL
}
API.get(apiName, path, myInit).then(response => {
// Add your code here
});
This will be a signed request to your AWS resources.
More here:
http://docs.aws.amazon.com/aws-mobile/latest/developerguide/web-getting-started.html

Related

Can we implement frontend and backend separately on AWS Elastic beanstalk?

I have frontend and backend both are using nodejs. Frontend is exposed and every request for api goes through the proxy module in the frontend, and both frontend and backend communicate on different modes.
Is there a way to deploy the above module, using code pipeline onto the Elastic Beanstalk platform ?
Why not deploy the front end on Amplify AWS?
AWS Amplify is a set of tools and services that can be used together or on their own, to help front-end web and mobile developers build scalable full stack applications, powered by AWS.
You just need to link your Repo and select your branch and everything will be deployed and generate also a random free domain or you can set your domain from the domain management section

best practice to deploy nodejs app on aws ec2 instance

I have deployed nodejs app on ec2 instance. I have used atlas for mongoDB, load balancer, Aws ssl to secure the connection and pm2. As iam already using aws load balancer should i need to use nginx. What is the best practice of deploying nodejs app on ec2. if i need to use ngnix where to configure http to https redirect?
Looks like you need a web application to be developed. I would suggest below architecture. enter image description here. This will eliminate pain of hosting/maintaining servers.
All AWS components can be programmatically integrated using AWS SDK and Amplify is a wrapper on top of this.
Develop your UI in any JavaScript framework and host it in AWS S3. Using CloudFront you can cache the UI layer. Put an API gateway layer which will intercept all the traffic from your UI. Using AWS Amplify can very much simplify your UI development with a lot of built-in wrapper components. It comes with CLI which can be used for deployment as well.
Host your Spring Boot+DB Driver (or NodeJS/C#/PHP/Python/etc.) Application with Rest API in AWS Beanstalk. BeanStalk can be configured with Load Balancing, Auto Scaling Group, etc. If AWS Beanstalk seems complicated for you, consider using AWS Lambda (Serverless, microservices) architecture.
AWS DocumentDB is a MongoDB extension and maybe you can leverage it. Which is again a highly scalable, very flexible NoSQL in this case.
You can leverage AWS Cognito (https://www.slideshare.net/awsugkochi/acdkochi19-enterprise-grade-security-for-web-and-mobile-applications-on-aws)to store User credentials in groups and add permissions and authenticate/authorise the users.
In API Gateway you can configure AWS Cognito Authoriser and protect the APIs from un-authorised calls.
Some of the auxiliary services can be used to integrate email/SMS etc. AWS SNS (Pub/Sub) + SQS (Queue) -> If you want to decouple any process, you can use SNS + SQS. You can send e-mails using AWS SES. AWS Route53 is the DNS and your domain can be hosted here.
If you have to upload any files to cloud and store it for users, leverage AWS S3.
You need to protect internet-facing components like API Gateway and Cloudfront using AWS WAF.
All these systems generate logs and it can be accessed from AWS cloudwatch. Your APIs can be monitored for performance and errors using AWS X-Ray.

Which is the best approach to deploy MERN stack app on AMAZON EC2?

I am googling a lot to be sure the best approach to deploy MERN stack app on aws ec2 ... in some examples Nginx being used in server (expressjs) part and in some cases its being used for Recatjs part and the express js part is just hosted in node , React even can be hosted in s3 I guesss .. so what is the best approach however?
Without configuring the server yourself in EC2, you can simply use managed Node.js hosting provided by AWS Elastic Beanstalk.
If you want to directly configure EC2 instance and deploy, you can follow this tutorial to do the deployment https://jasonwatmore.com/post/2019/11/18/react-nodejs-on-aws-how-to-deploy-a-mern-stack-app-to-amazon-ec2

I have an angular app with a Node server - no DB yet. How to deploy on AWS?

I'm not sure where and how to start with AWS for deploying, very confused at the moment. It seems like I deploy my server on Elastic Beanstalk, but then where does my build and static files go? S3 I'm guessing? Should I just follow the tutorial for Beanstalk? Thanks!
You can use Elastic Beanstalk to host your entire application including Static files where it will resides in the web server.
The downside of it is the performance for large scale applications where you can leverage AWS S3 and CloudFront. So if you are a starter with AWS, then I would recommend to consider Elastic Beanstalk for entire application hosting for the moment.

deploy a nodejs app using a chromebook

I have developed a nodejs app using cloud9IDE on my chromebook. It seems that I cannot install the package management applications needed to deploy to a hosting site such as nodejitsu or heroku. However it seems that I can upload an app folder to AWS elastic beanstalk, but I am a little scared of their pricing model.
Do I have any other option besides AWS (and buying a new computer)?

Resources