How to do migration of data from RDS to S3 using AWS Database Migration Service
Tags: awss3, awsrds, aws, awsdatabasemigrationservice
Published: 2021-09-12 18:46:51

“Challenges faced to find the solution of how to migrate the data from rds to s3”. Firstly I have checked various methods from which I can do the migration. I got AWS Datapipeline, AWS Glue, manually from rds export option or AWS Database migration service. I have also checked the costing of services as per the budget and scenario. Finally taken database migration service to do migration of data from rds to s3. 

AWS Database Migration Service helps you migrate databases to AWS quickly and securely. The source database remains fully operational during the migration, minimizing downtime to applications that rely on the database. The AWS Database Migration Service can migrate your data to and from most widely used commercial and open-source databases.

AWS Database Migration Service supports homogeneous migrations such as Oracle to Oracle, as well as heterogeneous migrations between different database platforms, such as Oracle or Microsoft SQL Server to Amazon Aurora. With AWS Database Migration Service, you can continuously replicate your data with high availability and consolidate databases into a petabyte-scale data warehouse by streaming data to Amazon Redshift and Amazon S3. [Learn more](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.html) about the supported source and target databases. To learn more, read the [AWS Database Migration Service](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html).
 
In this post, you will get to know how to do migration of data from RDS to S3 using AWS database migration service. Here I have taken an S3 bucket, ec2 server and rds. And then created an IAM role and AWS database migration service in which migration of data from rds to s3 is to be done.

#Prerequisites
You’ll need an Amazon Simple Storage Service, Amazon Elastic Compute Cloud and Amazon Relational Database Service for this post. [Getting started with Amazon Simple Storage Service](https://aws.amazon.com/s3/getting-started/) provides instructions on how to create a bucket in simple storage service. [Getting started with Amazon Elastic Compute Cloud](https://aws.amazon.com/ec2/getting-started/) provides instructions on how to create an ec2 server. [Getting started with Amazon Relational Database Service](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.htm) provides instructions on how to create a relational database. For this blog, I assume that I have a bucket, ec2 server and rds.

#Architecture Overview    
Diagram 1                                                                                                       
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ea1t1oow4bld6m5kh3ah.jpeg)
Diagram 2
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5j8wqe1qbw5xamb7efge.jpeg)
The architectural diagrams show the overall deployment architecture with data flow, AWS S3, EC2 instance, RDS and AWS DMS.

#Solution overview
The blog post consists of the following phases:
1. Create IAM role and replication instance in AWS Database Migration Service
2. Create the source and target endpoint for migration of data in database migration service
3. Create a database migration task for migrating the existing data from source to target
4. Testing for migration of data from rds to s3 using database migration service task

I have a S3 bucket, ec2 server and rds as below →
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eu6p82dzmp1eq38yif4g.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vdxbrq0slyditwjmgrag.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xmqrsfj0aqj3zwgynxwa.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pqlah74jquai24maaccj.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gd8whfs2ahpie4spdas2.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmjujmquwraydwe946yy.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wyvy1k0g1ckpdmrharra.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i392al05heeuhynrvq78.png)

##Phase 1: Create IAM role and replication instance in AWS Database Migration Service
1. Open the IAM console and create a role named as mysqltos3 with amazonrdsfullaccess and amazons3fullaccess.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jbtew4cscb8j67hghoa9.png)
2. Open the AWS Database Migration Service console and click on create replication instance.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcutgt9xb2wmruurnper.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58ifht914vztzsnxjbci.png)
3. Give the name of the replication instance as dmsreplicationinstance and choose the instance class as dms.t3.medium (or as per requirement). Set engine version, storage, vpc, publicly accessible, subnet group, availability zone, security group and kms as per requirement with default settings and create the replication instance. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/55twmpykxj7534tnde9a.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1b4wgoosg4z97qek2fo.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztwowu2kxgmgqgbjhugo.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6g0w5wvdkgrt150ariwp.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5q9r44y36k46qiudspp.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4tjuc4jpmmn0jhlodoxb.png)
4. Once the replication instance is in an available state, we can check all the configured details of the replication instance created.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k336dlgyq03pohulsjya.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xeduu3u2y2jfurq8iokd.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m8m523pqp9batb2kaomx.png)

##Phase 2: Create the source and target endpoint for migration of data in database migration service
1. In AWS Database Migration Service, Create the source endpoint. Select the rds db instance checkbox and then choose the rds instance. Set the endpoint database access option as provide access information manually, Input other required details in it with default kms key. Run the test with the default option set. Once the test is successful, create the source endpoint.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7gz2d3r868ud6oa9w2vx.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9xji9qh2mtdoj2url05.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7vq4punlse9xzheujwe.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ahzxadivjhph4p23qgw.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfcgs0gfh4r1533sqm5q.png)            
2. In AWS Database Migration Service, Create the target endpoint. Set the endpoint identifier as s3 target and choose the target as aws s3. Input the service access arn role and bucket name created earlier. Input other required details in it with default kms key. Run the test with the default option set. Once the test is successful, create the target endpoint. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hx52z0k1qkhcg7j4w197.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ooh4yynwgckgmg176o3.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivm7adx36kt42ntb3gya.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dri2a9nakmhykyy92v65.png)
3. Get the source and target endpoint in active state once completed successfully.     
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uue1w50bsnh6065t78fu.png)

##Phase 3: Create a database migration task for migrating the existing data from source to target 
1. In AWS database migration service, create a database migration task named as dmsreplicationtaskofexisting. Select the replication instance, source endpoint, target endpoint and migration type as migrate existing data. Set target table mode as drop tables on target and leave other options as default.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8f5j879oyq3s5qv614wj.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h51lftuqvtwu0j9iqq1u.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebh8kc5qsqc97kqn81xz.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4pcgjh604kxy7kc5npe.png) 
2. In the selection rule for table mapping, choose enter a schema, schema name as %, table name as % and action as include. We can set the mode of migration task automatically on creation or manually later, so i have chosen manually later. And created the data migration task.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixha29uk28xewflmdb6y.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51g2mkzmy1c6wccudrj1.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/740bx20a2thf9pix8a8p.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6cbav0y0if29pzzws06r.png)

##Phase 4: Testing for migration of data from rds to s3 using database migration service task
1. Login to ec2 server, run the command for login to mysql database using master username and password credentials. Then import the dump database to rds using the command line.           
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdfjs0cf4e41bsxcvlte.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8o6td1nwqi4w9rh7debq.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgyb8j7tb0fndf7ql2e5.png)
2. Start the data migration task by modifying the task created, once the replication is started it will replicate all data to s3 bucket created. Also can see the status of running the task with the number of tables completed to load in s3. We can see the migration activity on the console of table statistics in the database migration task running console.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ph9m7pm8v9zxiy2dwx19.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zyf0vfyrmdm928sdr1y.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/06zwi9rqf90k0byer0rt.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2ekr1u3nzp39u3jarv0.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hy5hfoam8baavbxl24m5.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vz9emnhdhzni9yk99a8x.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5vbyme0daace33zu0gfr.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7qzn83i7m4rtcsiw36xo.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ccsjhcp5fp02ds7omt9.png) 
3. Checkout the s3 bucket where we can get the output as a database folder wise and tables in csv format. We can check and compare the database name from the server terminal with s3 bucket database folders. Also checkout the metrics in cloudwatch. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pi88uwh75zkhikpwshe5.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8wxqbcdhwzs63wme8m50.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w1q5fmp636wcp6mcm5y4.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dw45l35cue6id7iowht4.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nudu0w4a9lhguq64klv2.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csmi40gyb2jpwrgxwlh8.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uwiyg8vlm7ccfhv8jbh4.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytb8n6c3ct8kenvvy12f.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7ym3anj2muij7g6o2jw.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99lyg6leh0jvbx5ajpez.png)

#Clean-up
Delete the environment as: S3 bucket, EC2 server, RDS, IAM role, AWS Database Migration Service.

#Pricing
I review the pricing and estimated cost of this example - 
For Simple Storage Service →
Cost = $0.01
For Relational Database Service →
Cost = $1.21
For Elastic Compute Cloud →
Cost = $0.20
For Database Migration Service →
Cost = $0.32
For cloudwatch, data transfer and kms (under free tier) →	 
Cost = $0.00 
Total Cost = $(0.01+1.21+0.20+0.32+0.00) = $1.74

#Summary
In this post, I have shown you how to do migration of data from rds to s3 using aws database migration service.
For more details on database migration service, Checkout Get started with AWS Database Migration Service - open the [AWS Database Migration Service console](https://ap-south-1.console.aws.amazon.com/dms/v2/home?region=ap-south-1#firstRun). To learn more, read the [AWS Database Migration Service documentation](https://docs.aws.amazon.com/dms/?id=docs_gateway). 

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)