Migrating On-Premises Web Server and Database to AWS: A Step-By-Step Guide
Tags: aws, cloud, devops, databasemigration
Published: 2023-05-01 02:13:46


![DMS Project Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16ix4vg8obw56jhr2wrj.png)
Migration to cloud services is increasingly becoming the norm as businesses seek to improve scalability, flexibility, and cost-efficiency. In this article, I'll guide you through my experience of migrating an on-premises web server and database to Amazon Web Services (AWS) using the AWS Database Migration Service (DMS).

**Establishing the Lab Environment**
The migration journey began by setting up the lab environment. To streamline this process, I used a CloudFormation template, which allowed me to create the necessary infrastructure on both the simulated on-premises and AWS side with just one click. The output included separate instances for the Web server and Database, VPCs, and related network resources like subnets and route tables.

**Creating a VPC Peering Connection**
Next, I created a VPC peering connection between the AWS and on-premises environments, simulating a Direct Connect or VPN connection between the two. I added a peering connection and updated the necessary routes to three Route Tables: On-prem-public router, AWS Private and Public Router. This connectivity is crucial for enabling seamless interaction between the two environments.

**Creating an RDS Instance and an EC2 Instance**
The third step involved creating an RDS Instance to move the on-premises database instance to AWS. While it was being provisioned, I concurrently created an AWS EC2 Instance with Apache and MariaDB to migrate the on-premises application server to the AWS EC2 Instance. This parallel task management significantly expedited the process.

**Migrating the Application Server**
I then migrated the application server, which involved copying all WordPress-related content from the on-premises application server to the AWS EC2 Instance. I accomplished this using secure copy (scp) via the CLI.

**Migrating the Database**
With the application server migration complete, I shifted my focus to migrating the on-premises database. I created a replication instance, and source & destination endpoints in DMS, to create a migration task. Once those were tested and confirmed operational, I executed a migration task to move the on-premises database to the AWS RDS Instance that I provisioned earlier.

**Updating Configurations**
As the final step of the migration process, I had to modify the AWS Application Server Database configurations as they were still pointing to the on-premises database instance. I updated them with the private IP address and credentials of the AWS RDS. To test the independent operation of the AWS Application server and RDS DB, I stopped the on-premises instances.

**Wrapping Up**
Once I confirmed that the migration of the on-premises environment to AWS was successful, I deleted all the resources I had created. This step is crucial to prevent unnecessary costs for resources that are no longer in use.

In conclusion, migrating an on-premises web server and database to AWS using AWS DMS is a systematic but straightforward process. It requires careful planning and execution but ultimately provides a scalable, flexible, and cost-efficient solution. The key takeaway is that while migrating to AWS can seem daunting, it's a manageable task with the right tools and step-by-step implementation.