Export Amazon RDS for SQL Server tables to an S3 bucket by using AWS DMS
Created by Subhani Shaik (AWS)
Environment: PoC or pilot | Source: RDS | Target: S3 |
R Type: N/A | Workload: Microsoft | Technologies: Databases; CloudNative |
AWS services: AWS DMS; Amazon RDS; Amazon S3; AWS Secrets Manager; AWS Identity and Access Management |
Summary
Amazon Relational Database Service (Amazon RDS) for SQL Server doesn’t support loading data onto other DB engine linked servers on the Amazon Web Services (AWS) Cloud. Instead, you can use AWS Database Migration Service (AWS DMS) to export Amazon RDS for SQL Server tables to an Amazon Simple Storage Service (Amazon S3) bucket, where the data is available to other DB engines.
AWS DMS 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. AWS DMS can migrate your data to and from the most widely used commercial and open-source databases.
This pattern uses AWS Secrets Manager while configuring the AWS DMS endpoints. Secrets Manager helps you protect secrets needed to access your applications, services, and IT resources. You can use the service to rotate, manage, and retrieve database credentials, API keys, and other secrets throughout their lifecycle. Users and applications retrieve secrets with a call to Secrets Manager, reducing the need to hardcode sensitive information. Secrets Manager offers secret rotation with built-in integration for Amazon RDS, Amazon Redshift, and Amazon DocumentDB. Also, the service is extensible to other types of secrets, including API keys and OAuth tokens. With Secrets Manager, you can control access to secrets by using fine-grained permissions and audit secret rotation centrally for resources in the AWS Cloud, third-party services, and on premises.
Prerequisites and limitations
Prerequisites
An active AWS account
An S3 bucket
A virtual private cloud (VPC)
A DB subnet
Amazon RDS for SQL Server
An AWS Identity and Access Management (IAM) role with access (list, get, and put objects) to the S3 bucket on behalf of the Amazon RDS instance.
Secrets Manager to store the RDS instance credentials.
Architecture
Technology stack
Amazon RDS for SQL Server
AWS DMS
Amazon S3
AWS Secrets Manager
Target architecture
The following diagram shows the architecture for importing data from the Amazon RDS instance to the S3 bucket with the help of AWS DMS.
The AWS DMS migration task connecting to the source Amazon RDS instance through the source endpoint
Copying data from the source Amazon RDS instance
The AWS DMS migration task connecting to the target S3 bucket through the target endpoint
Exporting copied data to the S3 bucket in comma-separated values (CSV) format
Tools
AWS services
AWS Database Migration Service (AWS DMS) helps you migrate data stores into the AWS Cloud or between combinations of cloud and on-premises setups.
AWS Identity and Access Management (IAM) helps you securely manage access to your AWS resources by controlling who is authenticated and authorized to use them.
Amazon Relational Database Service (Amazon RDS) helps you set up, operate, and scale a relational database in the AWS Cloud.
Amazon Simple Storage Service (Amazon S3) is a cloud-based object storage service that helps you store, protect, and retrieve any amount of data.
AWS Secrets Manager helps you replace hardcoded credentials in your code, including passwords, with an API call to Secrets Manager to retrieve the secret programmatically.
Other services
Microsoft SQL Server Management Studio (SSMS)
is a tool for managing SQL Server, including accessing, configuring, and administering SQL Server components.
Epics
Task | Description | Skills required |
---|---|---|
Create the Amazon RDS for SQL Server instance. |
| DBA, DevOps engineer |
Set up credentials for the instance. |
| DBA, DevOps engineer |
Configure the instance class, storage, auto scaling, and availability. |
| DBA, DevOps engineer |
Specify the VPC, subnet group, public access, and security group. | Select the VPC, DB subnet groups, and VPC security group as required to create the Amazon RDS instance. Follow the best practices, for example:
| DBA, DevOps engineer |
Configure monitoring, backup, and maintenance. |
| DBA, DevOps engineer |
Task | Description | Skills required |
---|---|---|
Create a table and load the example data. | In the new database, create a table. Use the example code in the Additional information section to load data into the table. | DBA, DevOps engineer |
Task | Description | Skills required |
---|---|---|
Create the secret. |
This secret will be used for the AWS DMS source endpoint. | DBA, DevOps engineer |
Task | Description | Skills required |
---|---|---|
Create an IAM role for access to Amazon RDS. |
| DBA, DevOps engineer |
Task | Description | Skills required |
---|---|---|
Create the S3 bucket. | To save the data from Amazon RDS for SQL Server, on the console, choose S3, and then choose Create bucket. Make sure that the S3 bucket is not publicly available. | DBA, DevOps engineer |
Task | Description | Skills required |
---|---|---|
Create an IAM role for AWS DMS to access Amazon S3. | Create an IAM role that allows AWS DMS to list, get, and put objects from the S3 bucket. | DBA, DevOps engineer |
Task | Description | Skills required |
---|---|---|
Create the AWS DMS source endpoint. |
| DBA, DevOps engineer |
Create the AWS DMS target endpoint. | Create the Target endpoint, selecting Amazon S3 as the Target engine. Provide the S3 bucket name and folder name for the IAM role that you created previously. | DBA, DevOps engineer |
Create the AWS DMS replication instance. | In the same VPC, subnet, and security group, create the AWS DMS replication instance. For more information about choosing an instance class, see the AWS documentation. | DBA, DevOps engineer |
Create the AWS DMS migration task. | To export the data from Amazon RDS for SQL Server to the S3 bucket, create a database migration task. For the migration type, choose Migrate existing data. Select the AWS DMS endpoints and replication instance that you created. | DBA, DevOps engineer |
Task | Description | Skills required |
---|---|---|
Run the database migration task. | To export the SQL Server table data, start the database migration task. The task will export the data from Amazon RDS for SQL Server to the S3 bucket in CSV format. | DBA, DevOps engineer |
Task | Description | Skills required |
---|---|---|
Delete the resources. | To avoid incurring extra costs, use the console to delete the resources in the following order:
| DBA, DevOps engineer |
Related resources
Additional information
To create the database and table, and to load the example data, use the following code.
--Step1: Database creation in RDS SQL Server CREATE DATABASE [Test_DB] ON PRIMARY ( NAME = N'Test_DB', FILENAME = N'D:\rdsdbdata\DATA\Test_DB.mdf' , SIZE = 5120KB , FILEGROWTH = 10%) LOG ON ( NAME = N'Test_DB_log', FILENAME = N'D:\rdsdbdata\DATA\Test_DB_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%) GO --Step2: Create Table USE Test_DB GO Create Table Test_Table(ID int, Company Varchar(30), Location Varchar(20)) --Step3: Load sample data. USE Test_DB GO Insert into Test_Table values(1,'AnyCompany','India') Insert into Test_Table values(2,'AnyCompany','USA') Insert into Test_Table values(3,'AnyCompany','UK') Insert into Test_Table values(4,'AnyCompany','Hyderabad') Insert into Test_Table values(5,'AnyCompany','Banglore')