AWS Database Migration Service (AWS DMS) simplifies the process of migrating databases to the AWS Cloud. One of the notable capabilities of AWS DMS is its ability to facilitate data migration to and from Amazon Simple Storage Service (Amazon S3) from supported database sources, offering a robust pathway for businesses to transition their data infrastructure to the cloud.
For organizations using multiple AWS accounts, having source and target databases residing in different accounts is not uncommon. This necessitates a clear understanding of how to configure AWS DMS to effectively integrate with an S3 bucket as either a source or target, especially when these resources span across different accounts.
In this post, we delve into the intricacies of configuring AWS DMS replication instances to use an S3 bucket in a different account. We also explore the process of establishing a connection between AWS DMS Serverless and S3 buckets across distinct accounts.
Solution overview
In this post, we configure a cross-account S3 bucket for both AWS DMS provisioned and AWS DMS Serverless. We test the AWS DMS endpoint connectivity from Account A to the S3 bucket in Account B.
You can launch an AWS DMS replication instance in either a private or public subnet based on your use case. For private replication instances with version 3.4.7 and higher, you need a VPC endpoint for the replication instance to access the S3 bucket when used as source or a target. The requirement is the same when using AWS DMS Serverless for a cross-account S3 bucket as target.
The following diagram illustrates the solution architecture.
The steps in the following sections outline how to configure a cross-account S3 bucket with a provisioned private replication instance.
Prerequisites
To follow along with this post, you should have the following prerequisites:
Permissions to create an AWS Identity and Access Management (IAM) role, IAM policy, S3 bucket, AWS DMS endpoints, AWS DMS replication instance, and AWS DMS task
A virtual private cloud (VPC) and private subnet set up through Amazon Virtual Private Cloud (Amazon VPC)
Amazon S3 VPC endpoint
AWS DMS Serverless requires a service-linked role to exist in your account if you don’t have admin permissions
An S3 Bucket
An AWS DMS replication instance
Source and target endpoints
Configure Account A
Account A consists of AWS DMS and a S3 VPC endpoint. AWS DMS mainly needs a replication instance and replication endpoints.
Complete the following steps to set up your resources in Account A:
On the Amazon VPC console, choose the same AWS Region as your AWS DMS replication instance.
In the navigation pane, choose Endpoints.
Choose Create endpoint.
For Service category, select AWS services.
Under Services, filter for Amazon S3.
Select the Amazon S3 internet gateway.
For VPC, choose the same VPC as the AWS DMS replication instance.
For Route tables, select the applicable routes. Choose all the route tables associated with all subnets under your replication instance subnet group.
Under Policy, select Full access. If you want to restrict the VPC endpoint policy to allow access to specific VPC, choose Custom and use a policy creation tool to specify your own access control. The below is an example VPC endpoint policy to restrict access to specific VPC.
When the VPC endpoint is ready, continue with the subsequent steps.
Create an IAM role with the following Amazon S3 permission policy to allow AWS DMS to access the S3 bucket in Account B:
Add the following trust policy:
Create a provisioned replication instance in a private subnet. Lastly, you create your AWS DMS endpoints.
On the AWS DMS console, choose Endpoints in the navigation pane.
Choose Create endpoint, then select Source or Target as needed.
Enter the endpoint identifier and, choose Amazon S3.
Enter the IAM role ARN that you created in step 10 for Service Access Role ARN.
Enter the bucket name and bucket folder (optional) in Account B.
Under Endpoint settings, add your endpoint settings, if you have any. For more information, refer to the endpoint settings when using Amazon S3 as a source or target for AWS DMS.
When using Amazon S3 as a source, you must also provide an external table definition.
Choose Create endpoint.
Configure Account B
Account B consists of the target S3 bucket and bucket policy. The bucket policy allows the AWS DMS replication instance to connect to the S3 bucket from a different account (Account A).
Complete the following steps to set up your resources:
Create a S3 bucket
Add the following bucket policy to the S3 bucket:
If your S3 bucket in Account B is using customer managed AWS Key Management Service (AWS KMS) key for encryption, make sure the IAM role created in Account A has the required permission to use the KMS key along with the S3 bucket permissions. The AWS KMS key policy in Account B must grant access to the IAM role in Account A.
Note: We cannot do a direct copy of the contents of an Amazon S3 bucket in the AWS GovCloud (US) Regions to or from another standard AWS Regions. Refer for more information on How Amazon Simple Storage Service Differs for AWS GovCloud (US). Replace with AWS GovCloud Amazon S3 resource ARN (for example arn:aws-us-gov:s3:::buketname ) in the S3 access policies specified in this post to set up cross account S3 access within the GovCloud region across GovCloud accounts. Refer Amazon Resource Names (ARNs) in GovCloud Regions for more information.
Test the connection
Complete the following steps to test the connection from the AWS DMS replication instance in Account A to the S3 bucket in Account B:
On the AWS DMS console, navigate to the Amazon S3 endpoint you created.
Under Test endpoint connection, select your VPC and replication instance.
Choose Run test.
The following screenshot shows your successful AWS DMS endpoint connection.
AWS DMS Serverless
You can follow the preceding steps to configure Amazon S3 as a target for AWS DMS Serverless. The test endpoint connection when using AWS DMS Serverless will be done as part of the task creation process (as shown in the following screenshot).
As of this writing, you can’t use Amazon S3 as a source for AWS DMS Serverless. For supported sources and target for AWS DMS Serverless, refer to Supported Engine Versions.
Clean up
To avoid ongoing charges, delete the resources you created with this solution:
Delete the AWS DMS replication instance in Account A.
Delete the VPC endpoint in Account A.
Delete the S3 bucket in Account B.
Conclusion
In this post, we demonstrated how to configure a cross-account S3 bucket for AWS DMS provisioned and DMS Serverless using an IAM role and S3 bucket policy. We can use the above approach to migrate the data from various databases to an S3 bucket in a different account. Further, this data can be used for a range of use cases, such as data lakes, websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics.
If you have any questions or concerns, leave them in the comment section.
About the Authors
Ashika Chandrashekar is a Senior Cloud Support DBE with Amazon Web Services and subject matter expert for AWS DMS, Amazon RDS, and Amazon RDS for MySQL. She has over 7 years of experience working with relational databases and database migration. At AWS, she works with service teams, technical account managers, and Solutions Architects, and helps customers migrate database workloads to AWS.
Noorul Mahajabeen Mustafa is a Cloud Support DBE working with AWS for 2.5 years. With over 5 years of database experience, Noorul is also a subject matter expert in Amazon RDS for SQL Server and AWS DMS. She works with customers providing exceptional technical assistance in database migration, Amazon RDS infrastructure, monitoring, and security-related scenarios.
Ankit Jain is a Cloud Support DBE working with AWS for 2 years. Ankit is also a subject matter expert in AWS DMS. With a focus on providing excellent customer experiences in the AWS Cloud, he works with external customers to handle a variety of scenarios, such as troubleshooting Amazon RDS infrastructure and, assisting with AWS DMS migrations. He provides technical assistance to customers, guiding them to migrate, optimize, and navigate their journey in the AWS Cloud.
Read MoreAWS Database Blog