This repository contains step-by-step guide & resources for deploying a full-stack application from scratch in AWS
-
Resources: Deploy Django in AWS Ubuntu 20.04 using Gunicorn and Nginx.
-
Youtube: Deploy Django on AWS | Django Deployment NGINX GUNICORN | Django Deployment by Code Keen
-
Resources: How To Deploy a React Application with Nginx on Ubuntu 20.04 Digital Ocean or Deploy Your React App with AWS EC2
Deploying a React application to an AWS EC2 instance involves several steps. Here's a high-level overview of the process:
-
Set Up an AWS EC2 Instance:
- Sign in to your AWS Management Console.
- Navigate to the EC2 service and launch an EC2 instance. Make sure to choose an appropriate instance type and configure security groups to allow incoming traffic on the required ports (e.g., port 80 for HTTP).
-
SSH Access:
- Once your EC2 instance is up and running, you'll need SSH access to it. Use the private key associated with your instance to connect.
ssh -i your-private-key.pem ec2-user@your-instance-ip
-
Update the System:
- After connecting to your instance, update the system packages:
sudo yum update -y
-
Install Node.js and NPM:
- Install Node.js and npm to run your React application:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash source ~/.nvm/nvm.sh nvm install node
-
Deploy Your React Application:
- There are various ways to deploy a React app, but one common method is to use a version control system like Git. Clone your React app repository to your EC2 instance:
git clone your-repo-url
- Navigate to your React app directory and install the dependencies:
cd your-app-directory npm install
- Build your React app for production:
npm run build
-
Set Up a Web Server:
- You can use a web server like Nginx or Apache to serve your React app. Install and configure Nginx:
sudo yum install nginx -y sudo systemctl start nginx sudo systemctl enable nginx
- Create an Nginx server block (virtual host) configuration for your React app. This usually involves editing the
/etc/nginx/nginx.conf
file or creating a new configuration file in/etc/nginx/conf.d/
.
Example Nginx config:
server { listen 80; server_name your-domain.com; root /path/to/your/react/app/build; index index.html; location / { try_files $uri /index.html; } }
- Test the Nginx configuration and restart Nginx:
sudo nginx -t sudo systemctl restart nginx
-
Configure DNS:
- If you have a custom domain, configure the DNS settings to point to your EC2 instance's public IP address.
-
Secure Your Application:
- Consider setting up SSL/TLS using a service like AWS Certificate Manager or Let's Encrypt for secure HTTPS access to your application.
-
Monitoring and Maintenance:
- Set up monitoring, backups, and automated deployment processes as needed for your production environment.
-
Access Your React App:
- Visit your domain or public IP address in a web browser to access your deployed React application.
Remember that this is a simplified overview, and the exact steps may vary depending on your specific requirements and the AWS region you are using. Always follow best practices for security and performance when deploying to production environments.
- Youtube: How to Deploy NodeJS App on AWS EC2 instance | Run App as Background Service Using PM2 | Full Demo or Deploying an Express.js Node.js application to a production AWS EC2 instance involves several steps. Here's a general guide on how to do it:
-
Set Up an AWS EC2 Instance:
- Launch an EC2 instance on AWS with the desired specifications (e.g., choose an appropriate instance type and configure security groups).
- Ensure that the instance has an appropriate IAM role or permissions to access other AWS services if your application requires it.
-
SSH Access:
- Use SSH to connect to your EC2 instance. You will need the private key associated with your instance:
ssh -i your-private-key.pem ec2-user@your-instance-ip
-
Update the System:
- After connecting to your instance, update the system packages:
sudo yum update -y
-
Install Node.js and NPM:
- Install Node.js and npm to run your Express.js application:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash source ~/.nvm/nvm.sh nvm install node
-
Deploy Your Express.js Application:
- Transfer your Express.js application code to the EC2 instance. You can use tools like
scp
,rsync
, or Git to do this.
scp -i your-private-key.pem -r /path/to/your/app ec2-user@your-instance-ip:/path/to/destination
- Transfer your Express.js application code to the EC2 instance. You can use tools like
-
Install Application Dependencies:
- Navigate to your application directory on the EC2 instance and install the dependencies:
cd /path/to/your/app npm install --production
-
Set Up a Process Manager:
- Use a process manager like
pm2
to keep your Node.js application running in the background and automatically restart it if it crashes:
npm install pm2 -g pm2 start app.js
- You can configure
pm2
to start your application at system boot by running:
pm2 startup
- Save the current
pm2
processes:
pm2 save
- Use a process manager like
-
Set Up Nginx as a Reverse Proxy (Optional):
- To route HTTP requests to your Express.js application, you can use Nginx as a reverse proxy. Install Nginx (if not already installed):
sudo yum install nginx -y
- Create an Nginx server block configuration to proxy requests to your Node.js application. For example:
server { listen 80; server_name your-domain.com; location / { proxy_pass http://localhost:3000; # Assuming your Express app runs on port 3000 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
- Test the Nginx configuration and restart Nginx:
sudo nginx -t sudo systemctl restart nginx
-
Configure DNS:
- If you have a custom domain, configure the DNS settings to point to your EC2 instance's public IP address.
-
Security and SSL/TLS (Optional):
- Consider securing your application by setting up SSL/TLS using a service like AWS Certificate Manager or Let's Encrypt for HTTPS access.
-
Monitoring and Maintenance:
- Set up monitoring, backups, and automated deployment processes as needed for your production environment.
-
Access Your Express.js Application:
- Visit your domain or public IP address in a web browser to access your deployed Express.js application.
This is a general guide, and specific configurations may vary based on your application's requirements and AWS region. Ensure you follow best practices for security, performance, and scalability when deploying to a production environment.
- Youtube: Creating Hosted Zone in Route 53, Issuing SSL Certificate from ACM and Configuring Load Balancer or How to setup or Install SSL in AWS EC2 Instance 2020