Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VProfile Project — Lift & Shift to AWS

🎓 Guided Learning Project — This is a continuation of my vprofile-local on-premises project. Having manually provisioned and configured the full stack on a local machine using Vagrant and VirtualBox, the next step in the learning journey was to migrate the same infrastructure to AWS — replicating every service in the cloud without changing a single line of application code. Both projects were completed as guided walkthroughs following the course by hkhcoder.

💡 Why lift & shift? Before optimising for the cloud, it's important to understand how to move an existing workload as-is. This project builds that foundation — mapping each on-prem VM directly to an AWS equivalent — before exploring more cloud-native approaches.

A re-hosting (lift & shift) migration of the VProfile multi-tier Java web application from a local Vagrant/VirtualBox environment to AWS. The on-premises services are mapped 1-to-1 to equivalent AWS infrastructure with no code changes.


📐 Architecture Overview

User/Browser
     │
     ▼
[ Route 53 ]  ← DNS
     │
     ▼
[ Application Load Balancer ]  ← HTTPS Termination (replaces Nginx)
     │
     ▼
[ EC2: Tomcat (Auto Scaling Group) ]  ← Application Server
     │
     ├──► [ EC2: Memcache ]   ← DB Caching        (replaces Memcache VM)
     ├──► [ EC2: RabbitMQ ]   ← Message Broker     (replaces RabbitMQ VM)
     └──► [ EC2: MySQL ]      ← Relational DB       (replaces MySQL VM)

On-Premises → AWS Mapping

On-Prem AWS Equivalent Notes
Nginx VM Application Load Balancer HTTPS, SSL termination
Tomcat VM EC2 (Auto Scaling Group) Same AMI, same config
MySQL VM EC2 (or RDS) MariaDB on EC2
Memcache VM EC2 ElastiCache optional upgrade
RabbitMQ VM EC2 Amazon MQ optional upgrade
Vagrant hostmanager Route 53 Private Hosted Zone Internal DNS

🧰 Prerequisites

  • AWS Account with IAM user and programmatic access
  • AWS CLI configured locally
  • Key pair created in your target AWS region
  • Basic understanding of EC2, Security Groups, and ALB

🔐 Security Groups

Three security groups are required:

vprofile-elb-sg (Load Balancer)

Type Protocol Port Source
HTTPS TCP 443 0.0.0.0/0
HTTP TCP 80 0.0.0.0/0

vprofile-app-sg (Tomcat EC2)

Type Protocol Port Source
Custom TCP TCP 8080 vprofile-elb-sg
SSH TCP 22 My IP

vprofile-backend-sg (MySQL, Memcache, RabbitMQ)

Type Protocol Port Source
MySQL/Aurora TCP 3306 vprofile-app-sg
Custom TCP TCP 11211 vprofile-app-sg
Custom TCP TCP 5672 vprofile-app-sg
All Traffic All All vprofile-backend-sg (self-referencing)

🖥️ EC2 Instance Setup

All backend instances (MySQL, Memcache, RabbitMQ) use the same base AMI (Amazon Linux 2 / CentOS) and are launched in the vprofile-backend-sg security group.

MySQL EC2

Launch an instance and run:

dnf update -y
dnf install epel-release git mariadb-server -y
systemctl start mariadb && systemctl enable mariadb
mysql_secure_installation   # root password: admin123

# Create DB and user
mysql -u root -padmin123 <<EOF
CREATE DATABASE accounts;
GRANT ALL PRIVILEGES ON accounts.* TO 'admin'@'%' IDENTIFIED BY 'admin123';
FLUSH PRIVILEGES;
EOF

# Import schema
cd /tmp
git clone -b local https://github.com/hkhcoder/vprofile-project.git
mysql -u root -padmin123 accounts < vprofile-project/src/main/resources/db_backup.sql
systemctl restart mariadb

Memcache EC2

dnf install epel-release memcached -y
systemctl start memcached && systemctl enable memcached
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/sysconfig/memcached
systemctl restart memcached

RabbitMQ EC2

dnf install epel-release wget -y
dnf -y install centos-release-rabbitmq-38
dnf --enablerepo=centos-rabbitmq-38 -y install rabbitmq-server
systemctl enable --now rabbitmq-server

rabbitmqctl add_user test test
rabbitmqctl set_user_tags test administrator
rabbitmqctl set_permissions -p / test ".*" ".*" ".*"
systemctl restart rabbitmq-server

🌐 Route 53 — Private DNS

Create a Private Hosted Zone (e.g., vprofile.internal) in Route 53 and add the following A records pointing to the private IPs of your backend EC2s:

Record Points to
db01.vprofile.internal MySQL EC2 private IP
mc01.vprofile.internal Memcache EC2 private IP
rmq01.vprofile.internal RabbitMQ EC2 private IP

This replaces the /etc/hosts entries managed by Vagrant's hostmanager plugin in the on-premises setup.


📦 Build & Deploy to Tomcat EC2

1. Update application.properties

Point backend hostnames at your Route 53 DNS names:

jdbc.url=jdbc:mysql://db01.vprofile.internal:3306/accounts
memcached.active.host=mc01.vprofile.internal
rabbitmq.address=rmq01.vprofile.internal

2. Build the artifact locally

cd vprofile-project
export MAVEN_OPTS="-Xmx512m"
mvn install

3. Upload to S3 and pull on EC2

# Upload from local machine
aws s3 cp target/vprofile-v2.war s3://YOUR_BUCKET/vprofile-v2.war

# On the Tomcat EC2
aws s3 cp s3://YOUR_BUCKET/vprofile-v2.war /tmp/vprofile-v2.war
systemctl stop tomcat
rm -rf /usr/local/tomcat/webapps/ROOT*
cp /tmp/vprofile-v2.war /usr/local/tomcat/webapps/ROOT.war
chown tomcat.tomcat /usr/local/tomcat/webapps -R
systemctl start tomcat

⚖️ Application Load Balancer

  1. Create a Target Group pointing to the Tomcat EC2 on port 8080, health check path: /login
  2. Create an Application Load Balancer in vprofile-elb-sg
  3. Add an HTTPS listener (port 443) with an SSL certificate from ACM
  4. Forward traffic to the target group

🌍 Route 53 — Public DNS (Optional)

Create a public A record or CNAME in your domain pointing to the ALB DNS name:

vprofile.yourdomain.com → ALB DNS Name

✅ Verify the Stack

Navigate to:

https://vprofile.yourdomain.com

or via the ALB DNS name directly. You should see the VProfile login page.


🔄 On-Premises vs AWS Comparison

Aspect On-Premises (Vagrant) AWS (Lift & Shift)
Compute VirtualBox VMs EC2 Instances
DNS /etc/hosts via vagrant-hostmanager Route 53 Private Hosted Zone
Load Balancer Nginx reverse proxy Application Load Balancer
SSL Manual / none ACM Certificate
Storage Local disk EBS
Artifact delivery Local Maven build S3
Scalability Manual Auto Scaling Groups

🗂️ Project Structure

.
├── src/
│   └── main/
│       └── resources/
│           ├── application.properties   ← update with AWS DNS names
│           └── db_backup.sql
├── userdata/                            ← EC2 user data scripts (optional)
│   ├── mysql.sh
│   ├── memcache.sh
│   ├── rabbitmq.sh
│   └── tomcat.sh
└── README.md

🧹 Teardown

To avoid ongoing charges, terminate resources in this order:

  1. Delete the Load Balancer and Target Group
  2. Terminate all EC2 instances
  3. Delete the S3 bucket contents and bucket
  4. Delete Route 53 hosted zones
  5. Release any Elastic IPs

📚 Key Concepts Demonstrated

  • Lift & shift cloud migration strategy (re-hosting)
  • EC2 instance provisioning and configuration
  • Security group design for multi-tier architecture
  • Application Load Balancer with SSL termination via ACM
  • Private DNS with Route 53 hosted zones
  • S3 for artifact storage and delivery
  • IAM roles for EC2-to-S3 access

About

Lift & shift migration of a multi-tier Java app from on-premises Vagrant setup to AWS EC2 — continuation of vprofile-local

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages