Hey there, fellow developers! I wanted to share my recent experience setting up my first application on AWS EC2. I've been working on becoming an AWS Community Builder, and this project was an important step in that journey. If you're considering using EC2 for hosting, hopefully my experience will help make your process smoother.
What is EC2 and Why I Chose It
Amazon Elastic Compute Cloud (EC2) is basically AWS's virtual server offering. I chose EC2 because I wanted full control over my environment while still leveraging the reliability of AWS infrastructure. Plus, the free tier option was perfect for my initial testing phase.
Let's Get Started
Prerequisites
- An AWS account (obviously!)
- Basic command line knowledge
- A simple application to deploy (I used a Node.js app)
- About 30-45 minutes of your time
Step 1: Launching Your EC2 Instance
- Log into the AWS Management Console and navigate to EC2
- Click on "Launch Instance"
- Pick your Amazon Machine Image (AMI) - I went with Amazon Ubuntu Server 24.04 LTS because it's optimized for EC2 and has good support
- Choose an instance type - t2.micro is free tier eligible and works well for small apps
- Configure your instance details - I kept most settings at default
- Add storage - the default 8GB was enough for my app
- Add tags - I just tagged it with Name: MyFirstEC2
- Configure security group - This is crucial! I created a new security group and:
- Allowed SSH (port 22) from my IP address only
- Allowed HTTP (port 80) from anywhere
- Allowed HTTPS (port 443) from anywhere
- Review and launch - This is when AWS prompts you to create a key pair. Download it and keep it safe.
Step 2: Connecting to Your Instance
Wait for your instance to initialize (it'll show "running" status). Then:
# Connect via SSH
ssh -i your-key-file.pem ubuntu@your-instance-public-dns
For the public dns use your public IPV4 address
Step 3: Setting Up Your Server
Once connected, I ran:
# Update and Upgrade linux machine
sudo apt update && sudo apt upgrade
# Install node version manager (nvm) by typing the following at the command line.
sudo su -
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
# Activate nvm by typing the following at the command line.
. ~/.nvm/nvm.sh
# Use nvm to install the latest version of Node.js by typing the following at the command line.
nvm install node
# Test that node and npm are installed and running correctly by typing the following at the terminal:
node -v
npm -v
# To install git, run below commands in the terminal window:
sudo apt-get update -y
sudo apt-get install git -y
# Just to verify if system has git installed or not
git — version
Step 4: Deploying Your Application
I cloned my repo, installed dependencies, and started my app:
git clone https://github.com/your-username/your-repo.git
cd your-repo
npm install
npm run dev
After installing your project dependencies, enter your start script, for me it is npm run dev.
You should also know that once you close your ssh session the app would stop running, for my own project I am using pm2 as my process manager which is setup in the project. If you don't have it setup use the instructions below
# Install PM2
sudo npm install -g pm2
# Start your app with PM2
pm2 start app.js
# Make PM2 restart on server reboot
pm2 startup
Challenges I Faced
For the most part I didn't face any challenges, spinning up an ec2 instance for the first time was relatively easy.
Best Practices I Learned
- Security is paramount: Only open the ports you need, restrict SSH access to your IP
- Automate everything: Learn basic bash scripting to automate your setup
- Monitor your resources: AWS has great monitoring tools - use them!
Next Steps
Next I'll be sharing how to add environment variables to your project and domain configuration.
If you're just starting with AWS, I highly recommend their documentation - it's surprisingly readable and has great examples.
That's it for now! Feel free to comment with any questions or share your own EC2 experiences. I'm still learning and would love to hear your tips too!
Top comments (0)