Migrating on-premise resources to AWS

abhinav singhal
AWS Tip
Published in
7 min readFeb 23, 2023

--

In this project, we will migrate on-premise resources to AWS. In this example it’s going to be App Server and Database instance. As shown below in the diagram.

We will take On-premise app server and DB server to Amazon EC2 and Amazon RDS.

On AWS environment, this will be inside a VPC, so do it step by step. This is a great example to apply in the real world. So let’s get started.

Strategy :

  1. Planning: Sizing and prerequisites.

For planning we are going to document the Source and destination.As shown below. Below example is from a great tutorial found online.

Action:

  1. Create VPC: Go to AWS console and search for VPC in search. This will take you to vpc section

2. Create Subnet: Subnets are supposed to be created to have our App server and DB server inside a subnet.

So we created one public and two private Subnets. As shown below

3. Create Internet GateWay: Click on create an internet gateway and fill in the information as shown below

4. Gateway to VPC : Select Action and click on attach to VPC

5. Update Route Table: Create route table and update the route table

If you carefully observe this route table has the entry of the vpc that we created. and it only routes internally

Click on edit routes and update with the Internet Gateway that we saved as few steps back. This will allow our EC2 instances to get access to Internet i.e. access to outside world.

Review:

So far we have completed below. We created VPC, public subnet and two private subnets and associated Gateway to VPC. We also updated route for internet access.

6. Create EC2 instances: create EC2 instance free tier, select Ubuntu as OS

Don’t forget to enable the Public IP settings as well. By default it's disabled. This is required as we need to access EC2 instances from your local machine visa public IPV4 address.

Add security group

now click on launch instance.

7: Create RDS instance:

Connect to EC2 instance via GitBash from you local machine.

You will need your key that was being generated while setting EC2 instance. So navigate to the folder where this file is there. I personally prefer maintaining a directory where I can manage all these files properly.

SSH ubuntu@<<public IPV4>> -i <<SSH-KEY.pm file>>

Now we have all OS installed, run below set of commands to prepare the App server. This is just an example for a python based application. You can have your own set of installations in other examples.

# Pre-requisites steps to run in the EC2 instance (Application Server)

sudo apt-get update
sudo apt-get install python3-dev -y
sudo apt-get install libmysqlclient-dev -y
sudo apt-get install unzip -y
sudo apt-get install libpq-dev python-dev libxml2-dev libxslt1-dev libldap2-dev -y
sudo apt-get install libsasl2-dev libffi-dev -y

curl -O https://bootstrap.pypa.io/pip/3.6/get-pip.py ; python3 get-pip.py --user

export PATH=$PATH:/home/ubuntu/.local/bin/

pip3 install flask
pip3 install wtforms
pip3 install flask_mysqldb
pip3 install passlib

sudo apt install awscli -y
sudo apt-get install mysql-client -y

Dry run

In real world, We are going to move the files from on premise to S3. BIt fo this example let’s assume the files are already there on the S3 bucket.

AWS cli command to upload the files into S3, this can be a faster way instead of using AWS console.

Once file are there on S3 bucket, then we will migrate the files to EC2 instance and the Database instance. Finally We will make connectivity between EC2 and Database. You can see it on diagram below. (steps 4,5,6).

Assume that Steps 1,2 and 3 are already done. i.e. S3 bucket already has the files from on premise server.

update the security group inboud settings to allow anyone to connect to RDS. Please note that this is only for this setting and not for production purpose.

Navigate to EC2 instance and copy the public IP address to that we can access via git bash.

ssh ubuntu@18.213.150.12 -i ssh-key-1.pem

Once done, you should be in EC2 instance which has Unbuntu installed. Now we can start downloading the files from s3 bucket, we can use wget command as shown below.

wget https://tcb-bootcamps.s3.amazonaws.com/bootcamp-aws/en/wikiapp-en.zip
wget https://tcb-bootcamps.s3.amazonaws.com/bootcamp-aws/en/dump-en.sql
  • Connect to MySQL running on AWS RDS via git bash.

Below is the command we are going to use to connect. The URI for your RDS can be taken from AWS console

mysql -h <RDS_ENDPOINT> -P 3306 -u admin -p
mysql -h awsuse1db01.chpxdvt5utej.us-east-1.rds.amazonaws.com -P 3306 -u admin -p

Once we connect to DB, now we are going to run some commands

#Create the wiki DB and import data

create database wikidb;
use wikidb;
source dump-en.sql;

above steps will create tables in the DB and insert data into it. the tables are articles and users.

Next we are going to create another user and add priviligies to it.

- Create the user wiki in the wikidb

CREATE USER wiki@'%' IDENTIFIED BY 'wiki123456';

GRANT ALL PRIVILEGES ON wikidb.* TO wiki@'%';

FLUSH PRIVILEGES;

Now exit out of RDS so that we are back to Operating system. So use the command exit;

now let’s unzip the application files and work on unzipped directory

#Unzip the app files

unzip wikiapp-en.zip
cd wikiapp

this is the configuration file from the application. let’s get into wiki.py file using vi editor

Here we have to update the DB hostname,this db hostname we got in previous step as well. type below command

  1. vi wiki.py
  2. press key I to insert the dbhost name

now press escape and :x to get out of editor and save it.

Let’s connect the python application to the database. to do this use command

python3 wiki.py

application is coming as shown below

Now lets test the application via EC2 instance public IP.

copy the Public IP from EC2 instance and add the post 8080 to it on a web-browser. This should show the landing page of your application.

Adding more articles on this sample application

I hope you liked this article and we will show case more in upcoming articles. Keep learning more and more.

--

--

SE-Manager #Hiring #Mentorship #DEI #SoftwareDelivery #KPI #OKR #java-J2EE #Nodejs #GraphQl #Aws