Deploying a project on AWS can seem complicated at first, especially if you are new to cloud computing. However, once you understand the basic workflow, deploying a project on an AWS EC2 instance becomes straightforward.
In this article, we will go through the complete process of uploading a project to AWS, setting up an EC2 server, transferring the project, installing the required dependencies, and running the application.
What is AWS EC2?
Amazon EC2 (Elastic Compute Cloud) provides virtual servers in the AWS cloud.
Instead of running your application only on your personal laptop, you can deploy it on an EC2 instance so that it can be accessed remotely over the internet.
The basic deployment flow looks like this:
Local Computer
↓
GitHub
↓
AWS EC2
↓
Install Dependencies
↓
Run Application
↓
Access Through Public IP
Prerequisites
Before starting, you should have:
- An AWS account
- Your project ready
- Basic knowledge of Linux commands
- Git installed
- Your project pushed to GitHub
- An SSH client such as PowerShell, Terminal, or PuTTY
- A working application that can run locally
For example, if you have a Node.js project:
npm install
npm start
If this works locally, you can proceed with deployment.
Step 1: Create an EC2 Instance
Log in to the AWS Management Console and search for EC2.
Click:
EC2 → Instances → Launch Instance
Give your instance a name, for example:
my-project-server
Choose an operating system.
For beginners, Ubuntu Server LTS is a good choice because it has extensive documentation and community support.
Select an appropriate instance type according to your project requirements.
For a small learning project, a low-cost/free-tier-eligible instance may be sufficient, depending on your AWS account and current AWS pricing/free-tier eligibility.
Step 2: Create an SSH Key Pair
During instance creation, AWS will ask you to create or select a key pair.
For example:
my-project-key.pem
Download the ".pem" file and keep it secure.
You need this key to connect to your EC2 server.
Never upload your private key to GitHub or include it inside your project.
Step 3: Configure Security Groups
A security group acts like a firewall for your EC2 instance.
For example, you may need these inbound rules:
| Type | Port | Purpose |
|---|---|---|
| SSH | 22 | Connect to server |
| HTTP | 80 | Web traffic |
| HTTPS | 443 | Secure web traffic |
| Custom TCP | 3000 | Node.js application |
| Custom TCP | 8080 | Java/Spring Boot application |
For SSH, it is better to restrict access to your IP address rather than allowing SSH from anywhere.
For a production application, you generally should not expose your application's internal port directly to the internet. A reverse proxy such as Nginx can listen on ports 80/443 and forward requests to your application.
Step 4: Connect to Your EC2 Instance
Once the instance is running, AWS will provide its public IPv4 address.
It may look like:
13.234.XX.XX
On Linux or macOS, you can connect using:
ssh -i "my-project-key.pem" ubuntu@YOUR_PUBLIC_IP
For example:
ssh -i "my-project-key.pem" ubuntu@13.234.XX.XX
On Windows, you can use PowerShell, Windows Terminal, or another SSH-compatible client.
If you are using an Amazon Linux AMI, the username may be different, commonly:
ec2-user
Step 5: Update the Server
After connecting to your EC2 instance, update the installed packages.
For Ubuntu:
sudo apt update
sudo apt upgrade -y
This ensures that the server has the latest available package updates.
Step 6: Install Git
If your project is stored on GitHub, install Git:
sudo apt install git -y
Verify the installation:
git --version
You should see something similar to:
git version 2.x.x
Step 7: Upload Your Project
There are several ways to upload a project to EC2.
The easiest approach for most developers is GitHub.
Go to the directory where you want to store your project:
cd ~
Clone your repository:
git clone https://github.com/USERNAME/PROJECT_NAME.git
Then enter the project directory:
cd PROJECT_NAME
Your project is now available on the EC2 server.
Step 8: Install the Required Environment
The required software depends on your project.
For Node.js
Install Node.js using an appropriate supported version, then verify:
node -v
npm -v
Install project dependencies:
npm install
For Java/Spring Boot
Install a compatible JDK:
sudo apt install openjdk-21-jdk -y
Check:
java -version
If your project uses Maven, you can build it with:
./mvnw clean package
or:
mvn clean package
The generated ".jar" file can then be run with:
java -jar target/your-application.jar
For Python
Install Python and the required tools:
sudo apt install python3 python3-pip python3-venv -y
Create a virtual environment:
python3 -m venv venv
Activate it:
source venv/bin/activate
Install dependencies:
pip install -r requirements.txt
Step 9: Configure Environment Variables
Do not hard-code sensitive information such as:
- Database passwords
- API keys
- JWT secrets
- AWS credentials
- Third-party service credentials
Instead, configure environment variables on the server.
For example:
export DB_URL="your_database_url"
export JWT_SECRET="your_secret"
For a production application, use a proper secret-management solution such as AWS Secrets Manager or AWS Systems Manager Parameter Store rather than casually storing secrets in shell history or source code.
Step 10: Run Your Application
Now start your application.
For a Node.js project:
npm start
For a Spring Boot application:
java -jar target/application.jar
For a Python application:
python3 app.py
Your application may now be running on a port such as:
3000
or:
8080
Step 11: Configure the Application Port
Suppose your Node.js application runs on:
http://localhost:3000
Your application is currently accessible only from the EC2 machine itself.
You need to make the application accessible externally.
First, make sure your application listens on the appropriate interface.
For example, instead of binding only to:
localhost
your application may need to listen on:
0.0.0.0
Then ensure the required port is permitted by the EC2 security group.
For example:
Custom TCP
Port: 3000
Source: Your required source
You can then test:
http://YOUR_PUBLIC_IP:3000
Step 12: Use Nginx for a Production Deployment
For a real application, exposing:
http://YOUR_PUBLIC_IP:3000
is usually not the ideal final setup.
A better architecture is:
User
↓
HTTPS :443
↓
Nginx
↓
Application :3000
Nginx acts as a reverse proxy.
Install it:
sudo apt install nginx -y
Then configure Nginx to forward requests to your application.
For example:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
After configuring Nginx:
sudo nginx -t
If the configuration is valid:
sudo systemctl restart nginx
Now users can access your application through your domain rather than directly using the application port.
Step 13: Keep Your Application Running
There is an important problem with simply running:
npm start
If you close your SSH session, the application may stop depending on how it was launched.
For Node.js applications, PM2 is a popular process manager.
Install it:
sudo npm install -g pm2
Start your application:
pm2 start npm --name "my-app" -- start
Check the status:
pm2 status
View logs:
pm2 logs
PM2 can also restart your application if it crashes.
Step 14: Connect a Domain Name
If you have a domain such as:
example.com
you can point the domain's DNS records to your AWS infrastructure.
For a simple setup, an A record can point the domain to the EC2 public IPv4 address.
However, EC2 public IP addresses can change when an instance is stopped and started.
For a more stable setup, use an Elastic IP or a more production-oriented AWS architecture.
Step 15: Enable HTTPS
You should use HTTPS for a production application.
A common setup is:
User
↓
HTTPS
↓
Nginx
↓
Application
A certificate can be obtained through Let's Encrypt/Certbot for many typical EC2 deployments.
HTTPS protects communication between the user and your server and is essential for modern web applications.
Updating Your Project
One major advantage of using GitHub is that updating your application becomes easy.
After making changes locally:
git add .
git commit -m "Update application"
git push
Then connect to your EC2 server and run:
git pull
Install any new dependencies if necessary:
npm install
Then restart your application.
For PM2:
pm2 restart my-app
Common Problems
1. Connection timed out
Usually check:
- EC2 instance is running
- Security group rules
- Correct public IP
- Correct SSH key
- Correct username
- Port configuration
2. Application works on localhost but not from the internet
Check:
- Security group
- Application binding address
- Application port
- Nginx configuration
For example, an application listening only on:
127.0.0.1:3000
cannot normally be reached directly from the internet.
3. Application stops after closing SSH
Use a process manager such as:
PM2
for Node.js or a proper Linux "systemd" service for applications such as Spring Boot.
4. Database connection fails
Check:
- Database URL
- Credentials
- Environment variables
- Network/security-group rules
- Whether the database allows connections from the EC2 server
Recommended Architecture
For a typical full-stack application, a reasonable AWS architecture could look like this:
┌──────────────┐
│ User │
└──────┬───────┘
│
HTTPS
│
┌──────▼───────┐
│ Nginx │
│ Reverse Proxy│
└──────┬───────┘
│
┌──────▼───────┐
│ Backend │
│ Node/Spring │
│ Boot │
└──────┬───────┘
│
┌──────▼───────┐
│ Database │
│ MongoDB/RDS │
└──────────────┘
For a React application, the frontend can also be deployed separately using services such as Amazon S3 + CloudFront, while the backend runs on EC2 or another compute service.
Final Deployment Checklist
Before considering your application deployed, verify:
- [ ] EC2 instance created
- [ ] SSH access working
- [ ] Security group configured
- [ ] Git installed
- [ ] Project cloned
- [ ] Required runtime installed
- [ ] Dependencies installed
- [ ] Environment variables configured
- [ ] Database connected
- [ ] Application running
- [ ] Required ports configured
- [ ] Nginx configured
- [ ] Domain connected
- [ ] HTTPS enabled
- [ ] Process manager/service configured
- [ ] Application tested from an external device
Conclusion
Deploying a project on AWS is essentially the process of moving your application from your local development environment to a cloud server and configuring everything required for users to access it.
The simplest learning path is:
GitHub
↓
AWS EC2
↓
Install Runtime
↓
Clone Project
↓
Install Dependencies
↓
Configure Environment Variables
↓
Run Application
↓
Nginx
↓
Domain + HTTPS
For learning AWS, EC2 is an excellent starting point, because it forces you to understand servers, Linux, networking, security groups, ports, processes, DNS, and reverse proxies. Once you understand this workflow, moving toward services such as ECS, Elastic Beanstalk, Lambda, RDS, S3, CloudFront, and CI/CD pipelines becomes much easier.
Top comments (0)