DEV Community

Revathi Joshi for AWS Community Builders

Posted on

Database Migration steps with the AWS CLI - 1

According to AWS documentation "AWS Database Migration Service (AWS DMS) is a cloud service that makes it possible to migrate relational databases, data warehouses, NoSQL databases, and other types of data stores. You can use AWS DMS to migrate your data into the AWS Cloud or between combinations of cloud and on-premises setups."

The process of Database Migration consists of creating and setting up a replication instance, source and target endpoints, and a replication task. The replication task runs on the replication instance and migrates data from the source endpoint to the target endpoint.

In the 1st article, Database Migration steps with the AWS CLI - 1, I will be showing on how to create and set up a replication instance, source and target endpoints.

The rest of the steps will be covered in my 2nd article.

You can use the AWS DMS console or the AWS CLI or the AWS SDK to perform the database migration.

Please visit my GitHub Repository for Database Migration articles on various topics being updated on constant basis.

Let’s get started!

Objectives:

1. Create a replication instance.

2. Describe the replication instance.

3. Create the source and target endpoints.

4. Test source and target endpoints from the replication instance.

5. Describe connections to the source and target endpoints.

Pre-requisites:

  • AWS user account with admin access, not a root account.
  • Cloud9 IDE with AWS CLI.

Resources Used:

AWS Database Migration Service

AWS CLI Command Reference on DMS

Steps for implementation to this project:

1. Create a replication instance.

  • A replication instance is an Amazon EC2 instance that can host
    replication tasks within AWS DMS.

  • Use the following command to create a replication instance with the name dms-instance.

dms-instance

aws dms create-replication-instance --replication-instance-identifier dms-instance --replication-instance-class dms.t2.micro --allocated-storage 50

Enter fullscreen mode Exit fullscreen mode
  • This command creates the replication instance on a t2.micro instance with 50 GB of allotted storage.

  • Use default values for other parameters.

2. Describe the replication instance.

  • Run the following command to describe the replication instance.

  • The response of this command will include the status of create-replication-instance.

aws dms describe-replication-instances --filter=Name=replication-instance-id,Values=dms-instance

Enter fullscreen mode Exit fullscreen mode
  • Run the following command to save the ReplicationInstanceArn for use in later steps.

ReplicationInstanceArn

rep_instance_arn=$(aws dms describe-replication-instances --filter=Name=replication-instance-id,Values=dms-instance --query 'ReplicationInstances[0].ReplicationInstanceArn' --output text)

Enter fullscreen mode Exit fullscreen mode
  • Wait 4-5 minutes to create the replication instance.

3. Create the source and target endpoints.

  • An endpoint describes the connection address, credentials, and other information required to connect to a database.

  • Run the following command to create the source and target endpoints.

  • Provide source and target database details like the engine-name, the hostname and port and the username and password.

source-endpoint

aws dms create-endpoint --endpoint-identifier source-endpoint --endpoint-type source --engine-name --username --password --server-name --port

Enter fullscreen mode Exit fullscreen mode

target-endpoint

aws dms create-endpoint --endpoint-identifier target-endpoint --endpoint-type target --engine-name --username --password --server-name --port

Enter fullscreen mode Exit fullscreen mode
  • Run the following commands to save the endpoint ARNs for use in later steps.

source_endpoint_arn

source_endpoint_arn=$(aws dms describe-endpoints --filter="Name=endpoint-id,Values=source-endpoint " --query="Endpoints[0].EndpointArn" --output text)

Enter fullscreen mode Exit fullscreen mode

target_endpoint_arn

target_endpoint_arn=$(aws dms describe-endpoints --filter="Name=endpoint-id,Values=target-endpoint" --query="Endpoints[0].EndpointArn" --output text) 

Enter fullscreen mode Exit fullscreen mode

4. Test source and target endpoints from the replication instance.

  • After the replication instance is active and the endpoints have been successfully created and before you save your endpoint, you should test the connection to ensure it was configured correctly.

  • Run the following commands to test connectivity tests from the replication instance to the database endpoints:

aws dms test-connection --replication-instance-arn $rep_instance_arn --endpoint-arn $source_endpoint_arn

Enter fullscreen mode Exit fullscreen mode
aws dms test-connection --replication-instance-arn $rep_instance_arn --endpoint-arn $target_endpoint_arn 

Enter fullscreen mode Exit fullscreen mode

5. Describe connections to the source and target endpoints.

  • Describe the connections to ensure that the tests are successful.

  • If the test connection fails, it must be fixed and retested.

aws dms describe-connections --filter "Name=endpoint-arn,Values=$source_endpoint_arn,$target_endpoint_arn"

Enter fullscreen mode Exit fullscreen mode

What we have done so far

We have successfully demonstrated on how to create and set up a replication instance, source and target endpoints.

Top comments (3)

Collapse
 
johntellsall profile image
John Mitchell

Love that you added the "test-connection" step! Looks useful, looking forward to next article.

Collapse
 
awsmine profile image
Revathi Joshi

Here is the 2nd article ---> Database Migration steps with the AWS CLI - 2

Collapse
 
awsmine profile image
Revathi Joshi

Thank you for your comments, John. Can we connect thru LinkedIn?