AWS RDS Cross Account data Migration Using AWS DMS

AWS DMS

In this blog, you will learn to migrate AWS RDS data from one account to another using AWS DMS (Database Migration Service).

In this guide, we focussed in PostgreSQL RDS databases. However, you can use this workflow and steps for any Database type.

For the migration we will make user of AWS Database Migration Service (DMS).

Database Migration Service Workflow

The following image shows the workflow of database migration using AWS DMS.

aws cross account rds data migration using the aws dms worlflow

DMS replication instance

First you need to understand about DMS replication instance. It is launched by AWS user which supports different instance classes (e.g., dms.t2.medium, dms.c5.large).

The size of the replication instance should be based on factors like data volume, workload, migration type (full load vs. ongoing replication), and performance requirements.

The DMS replication instance is responsible for,

  1. Data Extraction (reading from source database)
  2. Data Transformation (performs light transformations if required)
  3. Data Loading (Writes to target Database)
  4. Ongoing Replication ( For the replication instance to continuously replicate changes from the source to the target until cutover)

In this guide, we are going to do the following.

  1. The DMS replication instance will read the data from the source database via its endpoint.
  2. The VPC Peering connection will establish the private communication between the source and destination network.
  3. The replication instance will write the data to the destination database through the destination endpoint.

Steps For AWS RDS Cross Account Data Migration Using AWS DMS

Follow the steps to migrate AWS RDS data from one account to another using AWS DMS.

Step 1: Source RDS Parameter Group

The RDS Parameter Group is where we can pre-defined the database configurations.

By default, RDS creates a Parameter Group for each Database, but we can use a dedicated parameter group if we want a custom configuration.

I already have an RDS PostgreSQL database with data and have used a custom Parameter group.

To create a parameter group, follow the steps below.

parameter group creation for the source rds

In the next window, provide the following information.

  1. Engine type: A list of Database types will be available; choose the appropriate one.
  2. Parameter group family: The parameter group family should be the same version as the database.
  3. Type: Two types of Parameter Groups is available,
    • DB Parameter Group: For Database instance
    • DB Cluster Parameter Group: For Database cluster
aws rds parameter group configuration

The parameter group is now ready, and you can modify the parameters as required.

the modification of the aws rds custom parameter group

I have modified the following parameters.

rds.logical_replication = 1
max_wal_senders = 10
max_replication_slots = 10
wal_sender_timeout = 0
max_worker_processes = 8
max_logical_replication_workers = 8
max_parallel_workers = 8

Here’s what these parameters do:

  1. rds.logical_replication: Enable replication between databases.
  2. max_wal_senders: Maximum number of senders to transfer the changed data from the source to the destination.
  3. max_replication_slots: Maximum number of slots to store the changed data to transfer.
  4. wal_sender_timeout: Time to wait for the idle state senders.
  5. max_worker_process: The server can support the maximum number of background processes simultaneously within the database.
  6. max_logical_replication_workers: Maximum number of logical replication workers to copy data from one database to another.

max_parallel_workers: Maximum number of workers the system supports for the parallel operations.

Step 2: Source Database

I already have data in an RDS PostgreSQL database.

the rds configurations of the source database

Since this database has no public IP, it can only communicate with the internal network.

the configurations of the source rds

I created an EC2 instance within the same network to connect and verify the available database data.

the ec2 instance to connect the source rds and look the existing data

Use the following command to install the PostgreSQL Client on Amazon Linux 2023.

sudo dnf install postgresql15

Once the installation is completed, log in to Postgres using the following command.

psql -h <END_POINT> -p <PORT> -U <MASTER_USER_NAME> 

To list the available databases, use the following command.

\l

The source_db has data, so describe it to see what is inside.

the output of the available data of the source rds

To connect to the soure_db database

\c source_db

Now, list the tables inside the database

\dt
the existing databases of the source rds

To describe the available data in the table.

SELECT * FROM users;
the availabe data of the source rds database

Step 3: Virtual Private Network (VPC) for Both Accounts

We need a VPC in both accounts, and the VPC CIDR values should be different.

Source Account

Here, the source account VPC CIDR is 172.16.0.0/16, and the region I have chosen is the us-east-1

the vpc configuration of the source account
Destination Account

For the destination account, I have chosen the 10.0.0.0/16 CIDR VPC, and the region is us-east-1

the vpc configurations of the destination account

Step 4: VPC Peering

We can establish private communication between the two networks using a peering connection.

Source Account

We first need to establish the peering connection request from the source VPC.

the vpc peering dashboard of the source vpc

On the next page, provide the required information.

the vpc peering configurations of the source vpc to sent the request to the destination vpc.

After creating the peering connection, the request will go to the destination account, so we need to accept the request from the destination account.

Destination Account

Accept the peering request from the source account.

the vpc peering request from the destination vpc to accept to make the communication between networks

Step 5: Update Route Table

We need to modify both VPC Route Tables to route the traffic between the two networks through the peering connection.

Source Account

First, we updated the source account’s VPC Route Table Rules.

the modification of the rules in the source route table for the vpc peering

Edit routes to add new routes; in the new route, the Destination is the destination VPC CIDR 10.0.0.0/16 , and the Target is the Peering Connection.

the updated route table of the souce account
Destination Account

We update the destination account Route table with the source VPC details.

the updated route table of the destination account for the vpc peering route

Step 6: Create Destination Database

An RDS database will be created in the second AWS account, the US-east-1 region.

I created the same parameter group in the destination account with the same configurations.

the parameter group creation for the destination rds

I am provisioning a smaller database in the destination account because I have very little data in the source account to migrate.

the destination database creation, choosing the creation method and engine type

Choose the correct Database Engine version and the Template.

the database engine version and the templates for the destination rds creation

Settings section

Provide names for the DB instance identifier and Master username. I have selected the Self-managed option in Credential management, so I have to provide the password for the RDS manually.

the settings section of the rds creation and this section has the db identifier, credentials settings.

In the Connectivity section, select the VPC that has been Peered with the source account.

the connectivity section of the the destination rds which contains the compute resource, network type, vpc, subnet and public access.

the continuation of the connectivity configuration such as security group, availability zone, proxy and certificate authority

I am using the custom parameter group for the destination database.

adding the custom parameter group in the rds creation and the other settings such as backup and backup replication.

These are the only changes I have made in the destination database; the remaining configurations are by default.

The database will take a few minutes to up. Then, note down the destination database’s DB Identifier, Endpoint, and Port.

destination databse configuration after the creation of database

From the Configuration tab, note down the DB name and Master username.

the configuration tab details of the destination rds

Step 7: Create a DMS Replication Instance

The replication instance is a server that migrates data from the source database to the destination database.

The replication instance should be created on the source account to read the data from the source effectively.

the dms replication instance creation console

In the Settings, provide the instance configuration details such as Instance Class, Version, etc.

the dms replication instance creation configurations such as instance class, engine version, availability

Choose the appropriate storage for the replication instance.

the storage configuration of the dms replication instance

In the Connectivity and Security section, configure the VPC, Subnet, and accessibility configurations.

connectivity and security section of the dms replication instance and the configurations such as network type, vpc, subnet

I have selected the manual replication instance upgrade method in the Maintenance section.

the maintenance section of the dms replication instance such as maintenance window, auto version upgrade

It will take a few minutes for the status to be available for the replication instance.

the creation of the replication instance and the configurations.

Step 8: Create a DMS Endpoint

First, we need to create an endpoint for the source

the dms endpoint creation for the source endpoint

In the Endpoint Configuration, you need to provide the source RDS Identifier, engine type, user name, and password

the dms source endpoint creation configurations such as source rds engine, access and endpoint of the database, etc.

Finally, click the Run test; if it is successful, the endpoint is properly configured with the replication instance

We need to repeat the same process as the source endpoint to create a destination endpoint.

the endpoint creation of the destination rds

On the Endpoint configuration, you need to provide all the details manually.

the destination rds configurations such as engine type, access and endpoints, etc

Finally, a run test will be conducted to ensure the configurations are properly done.

the test connection of the destination endpoint

Both endpoints are configured, so we need to create a data migration task.

the endpoints of the source and destination rds

Step 9: Create a Data Migration Task

After configuring the source and destination endpoints, we must create a migration task to initiate the migration.

the dms migration task creation page

In the Task configuration section, we need to configure the Replication instance and source and destination endpoints.

Three migration types are available; we choose the one that migrates existing data and replicates ongoing changes.

So, any changes in the source database after the migration will also be reflected in the destination database.

dms task migration task configurations such as replication instance, source and destination endpoints and migration type

On the Task setting, I am going with the default configuration: Change Data Capture’s stop mode is disabled, the creation of a recovery table on the target DB is disabled, etc.

task setting secion ofo the dms migration task and the section contains custom CDC stop, recovery table creation, LOB column settings, etc.

I have turned off the data validation, but turning it on will ensure that the source and destination data are properly synced.

Also, the Task logs can be enabled to make alarms and notifications from the CloudWatch.

the dms migration task configurations such as data validation, task logs, batch optimization, contol table settings, etc

The Control table settings will create a database in the destination RDS containing information about the migration process.

full load tuning settings for the dms  migration task

In the Table mappings section, we can use the Selection Rules to filter the migration process by including or excluding tables, schemas, or databases.

table mapping configurations for the dms migration task and the configurations contains, selection rules and transformation rules

Premigration assessment will help identify possible issues before the migration starts, such as performance, compatibility, configuration, etc.

premigration assessment configuration for the dms migration task

After the task is created, migration will automatically start.

migration task completion and status

Note: If the migration is not started after few minutes, try using restart the task.

After the successful migration, you can see the following output.

detailed information fo the database migration using the aws dms

We can see more transfer details in the Task Statistics tab.

the table statistics section of the dms migration

Step 10: Validate the RDS to RDS Migration

We need to connect the RDS with an EC2 instance to view the migrated data from the destination account.

the validation of the database migration by connecting the destination database to an ec2 instance.

The data is successfully migrated from the source account to the destination account.

The migration task won’t stop until we stop it. It will keep syncing the data from source to destination, so if any new data is added or modified, it will reflect in the destination RDS.

Conclusion

The AWS Database Migration Service is a built-in service for migrating data between RDSs. Many more configurations are available to fulfill our requirements.

DMS can do continuous replication and migrate the data between different types of databases.

Serverless migration and convert data migration are also available in DMS.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like