Setting up Replication for AWS Database Migration Service

Posted by taufik

August 27, 2024

In this topic, you set up replication between the source and target databases. 

 

Step 1: Create a replication instance using the AWS DMS console 

To start work with AWS DMS, create a replication instance. 

A replication instance performs the actual data migration between source and target endpoints. Your instance needs enough storage and processing power to perform the tasks that migrate data from your source database to your target database. How large this replication instance should be depends on the amount of data to migrate and the tasks your instance needs to do. For more information about replication instances, see Working with an AWS DMS replication instance. 

 

To create a replication instance using the console 

1. Sign in to the AWS Management Console and open the AWS DMS console at https://console.aws.amazon.com/dms/v2/

2. On the navigation pane, choose Replication instances, and then choose Create replication instance.

3. On the Create replication instance page, specify your replication instance configuration:

  • For Name, enter DMS-instance.
  • For Description, enter a short description for your replication instance (optional).
  • For Instance class, leave dms.t3.medium chosen.
    The instance needs enough storage, networking, and processing power for your migration. For more information about how to choose an instance class, see Choosing the right AWS DMS replication instance for your migration.
  • For Engine version, accept the default.
  • For Multi AZ, choose Dev or test workload (Single-AZ).
  • For Allocated storage (GiB), accept the default of 50 GiB.
    In AWS DMS, storage is mostly used by log files and cached transactions. For cache transactions, storage is used only when the cached transactions need to be written to disk. As a result, AWS DMS doesn’t use a significant amount of storage.
  • For Network type choose IPv4.
  • For VPC, choose DMSVPC
  • For Replication subnet group, leave the replication subnet group currently chosen.
  • Clear Publicly accessible. 

4. Choose the Advanced security and network configuration tab to set values for network and encryption settings if you need them: 

  • For Availability zone, choose us-west-2a.
  • For VPC security group(s), choose the Default security group if it isn’t already chosen.
  • For AWS KMS key, leave (Default) aws/dms chosen. 

5. Leave the settings on the Maintenance tab as they are. The default is a 30-minute window selected at random from an 8-hour block of time for each AWS Region, occurring on a random day of the week. 

6. Choose Create. 

 AWS DMS creates a replication instance to perform your migration. 

 

Step 2: Specify source and target endpoints 

While your replication instance is being created, you can specify the source and target data store endpoints for the Amazon RDS databases you created previously. You create each endpoint separately. 

 

To specify a source endpoint and database endpoint using the AWS DMS console 

1. On the console, choose Endpoints from the navigation pane and then choose Create Endpoint. 

2. On the Create endpoint page, choose the Source endpoint type. Select the Select RDS DB instance box, and choose the dmsmariadb instance 

3. In the Endpoint configuration section, enter dms-mysql-source for Endpoint identifier. 

4. For Source engine, leave MySQL chosen. 

5. For Access to endpoint database, choose Provide access information manually. Verify that the Port, Secure Socket Layer (SSL) mode, User name, and Password are correct 

6. Choose the Test endpoint connection (optional) tab. For VPC, choose DMSVPC. 

7. For Replication instance, leave dms-instance chosen. 

8. Choose Run test.
After you choose Run test, AWS DMS creates the endpoint with the details that you provided and connects to it. If the connection fails, edit the endpoint definition and test the connection again. You can also delete the endpoint manually. 

9. After you have a successful test, choose Create endpoint. 

10. Specify a target database endpoint using the AWS DMS console. To do this, repeat the steps preceding, with the following settings: 

  • Endpoint type: Target endpoint 
  • RDS Instance: dms-postgresql 
  • Endpoint identifier: dms-postgresql-target 
  • Target engine: Leave PostgreSQL chosen. 

 When you’re finished providing all information for your endpoints, AWS DMS creates your source and target endpoints for use during database migration 

 

Step 3: Create a task and migrate data 

In this step, you create a task to migrate data between the databases you created. 

 

To create a migration task and start your database migration 

1. In the console navigation pane, choose Database migration tasks, and then choose Create task. The Create database migration task page opens. 

2. In the Task configuration section, specify the following task options: 

  • Task identifier: Enter dms-task. 
  • Replication instance: Choose your replication instance (dms-instance-vpc-<vpc id> 
  • Source database endpoint: Choose dms-mysql-source. 
  • Target database endpoint: Choose dms-postgresql-target. 
  • Migration type: Choose Migrate existing data and replicate on-going changes. 

3. Choose the Task settings tab. Set the following settings: 

  • Target table preparation mode: Do nothing 
  • Stop task after full load completes: Don’t stop 

4. Choose the Table mappings tab, and expand Selection rules. Choose Add new selection rule. Set the following settings: 

  • Schema: Enter a schema 
  • Schema name: dms_sample 

5. Choose the Migration task startup configuration tab, and then choose Automatically on create. 

6. Choose Create task. 

AWS DMS then creates the migration task and starts it. The initial database replication takes about 10 minutes. Make sure to do the next step in the tutorial before AWS DMS finishes migrating the data. 

 

Step 4: Test replication 

In this section, you insert data into the source database during and after initial replication, and query the target database for the inserted data. 

To test replication 

1. Make sure that your database migration task shows a status of Running but your initial database replication, started in the previous step, isn’t complete. 

2. Connect to your Amazon EC2 client, and start the MySQL client with the following command. Provide your MySQL database endpoint. 

mysql -h dms-mysql.abcdefg12345.us-west-2.rds.amazonaws.com -P 3306 -u admin -pchangeit dms_sample 

3. Run the following command to insert a record into the source database. 

MySQL [dms_sample]> insert person (full_name, last_name, first_name) VALUES (‘Test User1’, ‘User1’, ‘Test’); Query OK, 1 row affected (0.00 sec) 

4. Exit the MySQL client. 

MySQL [dms_sample]> exit
Bye 

5. Before replication completes, query the target database for the new record.
From the Amazon EC2 instance, connect to the target database using the following command, providing your target database endpoint. 

psql \ –host=dms-postgresql.abcdefg12345.us-west-2.rds.amazonaws.com \ –port=5432 \ –username=postgres \ –password \ –dbname=dms_sample 

Provide the password (changeit) when prompted. 

6. Before replication completes, query the target database for the new record. 

dms_sample=> select * from dms_sample.person where first_name = ‘Test’; id | full_name | last_name | first_name —-+———–+———–+———— (0 rows) 

7. While your migration task is running, you can monitor the progress of your database migration as it happens: 

  • In the DMS console navigation pane, choose Database migration tasks. 
  • Choose dms-task. 
  • Choose Table statistics. 

For more information about monitoring, see Monitoring AWS DMS tasks. 

8. After replication completes, query the target database again for the new record. AWS DMS migrates the new record after initial replication completes. 

dms_sample=> select * from dms_sample.person where first_name = ‘Test’; id | full_name | last_name | first_name ———+————+———–+———— 7077784 | Test User1 | User1 | Test (1 row) 

9. Exit the psql client. 

dms_sample=> quit 

10. Repeat step 1 to connect to the source database again. 

11. Insert another record into the person table. 

MySQL [dms_sample]> insert person (full_name, last_name, first_name) VALUES (‘Test User2’, ‘User2’, ‘Test’); Query OK, 1 row affected (0.00 sec) 

12. Repeat steps 3 and 4 to disconnect from the source database and connect to the target database. 

13. Query the target database for the replicated data again. 

dms_sample=> select * from dms_sample.person where first_name = ‘Test’; id | full_name | last_name | first_name ———+————+———–+———— 7077784 | Test User1 | User1 | Test 7077785 | Test User2 | User2 | Test (2 rows) 

 

Step 5: Clean up AWS DMS resources 

After you complete the getting started tutorial, you can delete the resources you created. You can use the AWS console to remove them. Make sure to delete the migration tasks before deleting the replication instance and endpoints. 

To delete a migration task using the console 

  • On the AWS DMS console navigation pane, choose Database migration tasks. 
  • Choose dms-task. 
  • Choose Actions, Delete. 

To delete a replication instance using the console 

  • On the AWS DMS console navigation pane, choose Replication instances. 
  • Choose DMS-instance. 
  • Choose Actions, Delete. 

 AWS DMS deletes the replication instance and removes it from the Replication instances page. 

 

To remove endpoints using the console 

  • On the AWS DMS console navigation pane, choose Endpoints. 
  • Choose dms-mysql-source. 
  • Choose Actions, Delete. 

After you delete your AWS DMS resources, make sure also to delete the following resources. For help with deleting resources in other services, see each service’s documentation. 

  • Your RDS databases. 
  • Your RDS database parameter groups. 
  • Your RDS subnet groups. 
  • Any Amazon CloudWatch logs that were created along with your databases and replication instance. 
  • Security groups that were created for your Amazon VPC and Amazon EC2 client. Make sure to remove the inbound rule from Default for the launch-wizard-1 security groups, which is necessary for you to be able delete them. 
  • Your Amazon EC2 client. 
  • Your Amazon VPC. 
  • Your Amazon EC2 key pair for your Amazon EC2 client. 

 

Credit to: AWS Documentation 

Privacy & Policy

PT Central Data Technology (“CDT” or “us”) is strongly committed to ensuring that your privacy is protected as utmost importance to us. https://centraldatatech.com/ , we shall govern your use of this website, including all pages within this website (collectively referred to herein below as this “Website”), we want to contribute to providing a safe and secure environment for visitors.

The following are terms of privacy policy (“Privacy Policy”) between you (“you” or “your”) and CDT. By accessing the website, you acknowledge that you have read, understood and agree to be bound by this Privacy Policy

Use of The Subscription Service by CDT and Our Customers

When you request information from CDT and supply information that personally identifies you or allows us to contact you, you agree to disclose that information with us. CDT may disclose such information for marketing, promotional and activity only for the purpose of CDT and the Website.

Collecting Information

You are free to explore the Website without providing any personal information about yourself. When you visit the Website or register for the subscription service, we provide some navigational information for you to fill out your personal information to access some content we offered.

CDT may collect your personal data such as your name, email address, company name, phone number and other information about yourself or your business. We are collecting your data in some ways, online and offline. CDT collects your data online using features of social media, email marketing, website, and cookies technology. We may collect your data offline in events like conference, gathering, workshop, etc. However, we will not use or disclose those informations with third party or send unsolicited email to any of the addresses we collect, without your express permission. We ensure that your personal identities will only be used in accordance with this Privacy Policy.

How CDT Use the Collected Information

CDT use the information that is collected only in compliance with this privacy policy. Customers who subscribe to our subscription services are obligated through our agreements with them to comply with this Privacy Policy.

In addition to the uses of your information, we may use your personal information to:

  • Improve your browsing experience by personalizing the websites and to improve the subscription services.
  • Send information about CDT.
  • Promote our services to you and share promotional and informational content with you in accordance with your communication preferences.
  • Send information to you regarding changes to our customers’ terms of service, Privacy Policy (including the cookie policy), or other legal agreements

Cookies Technology

Cookies are small pieces of data that the site transfers to the user’s computer hard drive when the user visits the website. Cookies can record your preferences when visiting a particular site and give the advantage of identifying the interest of our visitor for statistical analysis of our site. This information can enable us to improve the content, modifying and making our site more user friendly.

Cookies were used for some reasons such as technical reasons for our website to operate. Cookies also enable us to track and target the interest of our users to enhance the experience of our website and subscription service. This data is used to deliver customized content and promotions within the Helios to customers who have an interest on particular subjects.

You have the right to decide whether to accept or refuse cookies. You can edit your cookies preferences on browser setup. If you choose to refuse the cookies, you may still use our website though your access to some functionality and areas of our website may be restricted.

This Website may also display advertisements from third parties containing links to other websites of interest. Once you have used these links to leave our site, please note that we do not have any control over the website. CDT cannot be responsible for the protection and privacy of any information that you provide while visiting such websites and this Privacy Policy does not govern such websites.

Control Your Personal Data

CDT give control to you to manage your personal data. You can request access, correction, updates or deletion of your personal information. You may unsubscribe from our marketing activity by clicking unsubscribe us from the bottom of our email or contacting us directly to remove you from our subscription list.

We will keep your personal information accurate, and we allow you to correct or change your personal identifiable information through marketing@centraldatatech.com