Edwin Pradeep
4 min readJun 22, 2020

--

EC2-Classic to EC2-VPC Migration

Your AWS account might support both EC2-Classic and EC2-VPC, depending on when the AWS account was created and regions used.

AWS accounts created after 2009 do not support the EC2-Classic platform environment and have the EC2-VPC environment. EC2-VPC environment has additional advantages over the EC2-Classic environment. In terms of security, VPC has Network ACL which can allow or deny access to a particular IP. Also, we can setup OpenVPN and customer gateway between VPC and on-premises.

This blog will tell you how to migrate instances (both EC2 and RDS) from the EC2-classic environment to the EC2-VPC environment with zero downtime.

Let’s assume that I have my application server running in the cloud infrastructure. The following architecture diagram can represent the infrastructure running in the EC2-Classic environment.

As you can see in the diagram, there is a Route53 Entry for http://www.mysite.com with ‘A’ name record. There are two app servers running which are under a load balancer which are pointing to the MySQL RDS instance.

In order to migrate the above EC2-Classic environment to the EC2-VPC environment without downtime following steps can be used-

  1. Creating a Load Balancer inside the VPC.
  2. Creating AMI of the app server
  3. Launching application server into a public subnet of the VPC.
  4. Updating the DNS record in Route53.
  5. Creating Read-Replica of RDS instance and Creating snapshot from Read-Replica.
  6. Launching RDS instance from the snapshot into VPC.
  7. Removing replication.

One should have an understanding of EC2, VPC, RDS services and their corresponding terminologies in order to understand and implement these steps.

Let us assume that we have created a VPC with three public subnets.

Step 1: Creating a Load Balancer inside the VPC:

Step 2: Creating AMI of the Application server.

  1. Select your app server instance and right-click on it. Choose to Create Image option.
  2. Then, give the AMI name as App-server-AMI and add a description. Make sure that No Reboot Checkbox is selected.
  3. Click Create Image. It will create an AMI of this app server instance.

Step 3: Launching the application server into the public subnet of VPC.

Once the AMI creation process is completed, launch an instance into a public subnet of the VPC.

  1. Select AMI created in Step 1 and click Launch Instance.
  2. Launch this instance into the public subnet of the VPC.

The app server is launched into the public subnet of VPC. So, this instance is already configured with the endpoint of the RDS instance. If any request comes to this instance then it will contact the RDS database which is present in the EC2-classic environment.

Task 4: Updating DNS record in Route 53

Now we need to update the DNS or Route53 record with CNAME entry of our new load balancer with http://www.mysite.com.By default App server is pointing to endpoint of EC2-Classic RDS instance

Presently we have migrated the App server instance into VPC. Now we need to move the RDS instance from EC2-Classic environment into the EC2-VPC environment.

Task 5: Creating Read-Replica of RDS instance and Creating snapshot from Read-Replica.

The ‘new RDS’ will be launched in the VPC and the ‘source RDS’ is residing in EC2-classic.

  1. A new RDS security group (VPC) will be created having similar permissions as the old security group.
  2. A new DB subnet group and parameter group for a new RDS instance will be created which will be the same as the RDS security group and parameter group in EC2 classic.
  3. In the source RDS, a user with necessary permissions for replication will be created.
  4. Read replica will be created using the source RDS instance.
  5. The snapshot of reading replica will be created and a new RDS instance will be launched from the snapshot in one of the VPC subnets.

Task 6: Updating the application server to point to the new RDS.

Task 7: Stopping replication

Note: The new RDS instance launched will be publically accessible so as to fetch new writes from the source RDS instance. (Basically a master-slave configuration). Once all data is synchronized, the subnet of the RDS instance can be made private.

Stop replication between the RDS instances.

Now check if the site is working properly or not by entering its URL in the browser. If yes, then migration from EC2 Classic to VPC has completed successfully.

Hold tight… We are uploading new content soon!!!

--

--