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
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Give your instance a name, for example:
my-project-server
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
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 applicationFor 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
Enter fullscreen mode Exit fullscreen mode
On Linux or macOS, you can connect using:
ssh -i "my-project-key.pem" ubuntu@YOUR_PUBLIC_IP
Enter fullscreen mode Exit fullscreen mode
For example:
ssh -i "my-project-key.pem" [email protected]
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Step 5: Update the Server
After connecting to your EC2 instance, update the installed packages.
For Ubuntu:
sudo apt update
sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Verify the installation:
git --version
Enter fullscreen mode Exit fullscreen mode
You should see something similar to:
git version 2.x.x
Enter fullscreen mode Exit fullscreen mode
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 ~
Enter fullscreen mode Exit fullscreen mode
Clone your repository:
git clone https://github.com/USERNAME/PROJECT_NAME.git
Enter fullscreen mode Exit fullscreen mode
Then enter the project directory:
cd PROJECT_NAME
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Install project dependencies:
npm install
Enter fullscreen mode Exit fullscreen mode
For Java/Spring Boot
Install a compatible JDK:
sudo apt install openjdk-21-jdk -y
Enter fullscreen mode Exit fullscreen mode
Check:
java -version
Enter fullscreen mode Exit fullscreen mode
If your project uses Maven, you can build it with:
./mvnw clean package
Enter fullscreen mode Exit fullscreen mode
or:
mvn clean package
Enter fullscreen mode Exit fullscreen mode
The generated “.jar” file can then be run with:
java -jar target/your-application.jar
Enter fullscreen mode Exit fullscreen mode
For Python
Install Python and the required tools:
sudo apt install python3 python3-pip python3-venv -y
Enter fullscreen mode Exit fullscreen mode
Create a virtual environment:
python3 -m venv venv
Enter fullscreen mode Exit fullscreen mode
Activate it:
source venv/bin/activate
Enter fullscreen mode Exit fullscreen mode
Install dependencies:
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode
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"
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
For a Spring Boot application:
java -jar target/application.jar
Enter fullscreen mode Exit fullscreen mode
For a Python application:
python3 app.py
Enter fullscreen mode Exit fullscreen mode
Your application may now be running on a port such as:
3000
Enter fullscreen mode Exit fullscreen mode
or:
8080
Enter fullscreen mode Exit fullscreen mode
Step 11: Configure the Application Port
Suppose your Node.js application runs on:
http://localhost:3000
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
your application may need to listen on:
0.0.0.0
Enter fullscreen mode Exit fullscreen mode
Then ensure the required port is permitted by the EC2 security group.
For example:
Custom TCP
Port: 3000
Source: Your required source
Enter fullscreen mode Exit fullscreen mode
You can then test:
http://YOUR_PUBLIC_IP:3000
Enter fullscreen mode Exit fullscreen mode
Step 12: Use Nginx for a Production Deployment
For a real application, exposing:
http://YOUR_PUBLIC_IP:3000
Enter fullscreen mode Exit fullscreen mode
is usually not the ideal final setup.
A better architecture is:
User
↓
HTTPS :443
↓
Nginx
↓
Application :3000
Enter fullscreen mode Exit fullscreen mode
Nginx acts as a reverse proxy.
Install it:
sudo apt install nginx -y
Enter fullscreen mode Exit fullscreen mode
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;
}
}
Enter fullscreen mode Exit fullscreen mode
After configuring Nginx:
sudo nginx -t
Enter fullscreen mode Exit fullscreen mode
If the configuration is valid:
sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Start your application:
pm2 start npm --name "my-app" -- start
Enter fullscreen mode Exit fullscreen mode
Check the status:
pm2 status
Enter fullscreen mode Exit fullscreen mode
View logs:
pm2 logs
Enter fullscreen mode Exit fullscreen mode
PM2 can also restart your application if it crashes.
Step 14: Connect a Domain Name
If you have a domain such as:
example.com
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
Then connect to your EC2 server and run:
git pull
Enter fullscreen mode Exit fullscreen mode
Install any new dependencies if necessary:
npm install
Enter fullscreen mode Exit fullscreen mode
Then restart your application.
For PM2:
pm2 restart my-app
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
cannot normally be reached directly from the internet.
3. Application stops after closing SSH
Use a process manager such as:
PM2
Enter fullscreen mode Exit fullscreen mode
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 │
└──────────────┘
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode
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.
답글 남기기