
Cross-Account Amazon DocumentDB Migration with DMS: The Networking, Demystified
A step-by-step playbook for moving Amazon DocumentDB across AWS accounts with DMS, covering the VPC peering, DNS, routing, and security-group details that make or break the connection.
Cross-Account Amazon DocumentDB Migration with DMS: The Networking, Demystified
A customer recently asked me to help them migrate an Amazon DocumentDB cluster from one AWS account to another. "There's a blog for that," I said confidently, and pointed them at the AWS blog on cross-account replication with Amazon DocumentDB and AWS Database Migration Service (DMS) . Easy win, right?
Then I actually tried it.
The blog is a solid starting point, but it glosses over the part that can eat an entire afternoon: the networking. VPC peering, DNS resolution across accounts, route tables, and the security group choreography that must line up just so before DMS will connect to both clusters. I got it working and surprised myself, since I'm far from a networking expert, and wrote down the complete playbook, including all the connectivity plumbing the blog glosses over.
If you've ever watched a DMS "Test connection" spin for 60 seconds and then fail with a timeout that tells you absolutely nothing, this one's for you.
The challenge
Migrate an Amazon DocumentDB cluster in Account A (source) to Account B (target), using DMS. The catch: the two clusters live in different AWS accounts, in different VPCs, and DMS needs a clean network path to both before it will move a single document.
The high-level solution looks like this:

Pro tip: Put the replication instance in the source VPC, not the target. CDC replays every change off the source cluster change stream, so the closer the instance is to the source, the better your ongoing replication performance.
Before you start: two prerequisites that will bite you later if you skip them
1. Non-overlapping CIDR blocks
The VPCs in both accounts must have different IPv4 CIDR blocks. If they overlap, the peering connection simply won't establish, and you'll spend twenty minutes convinced you clicked the wrong button. You didn't. Your networks just collide. To check, do the following in both accounts:
- In the VPC console choose Your VPCs.
- Select the VPC hosting the Amazon DocumentDB cluster.
- Choose the CIDRs tab and note the block.
Confirm the two don't overlap before you go any further.
2. DNS resolution and DNS hostnames enabled
Both VPCs need DNS resolution and DNS hostnames turned on. This is the setting that makes cross-account name resolution work later. To enable, do the following in both accounts:
- In the VPC console choose Your VPCs.
- Select the VPC hosting the Amazon DocumentDB cluster.
- Choose Actions → Edit VPC settings.
- Under DNS settings, select both Enable DNS resolution and Enable DNS hostnames.
- Choose Save changes.
Demystifying the networking: building the network path
This section is the main event. Follow it in order, as most of the "why won't it connect?" pain comes from doing these steps out of sequence or skipping the DNS ones.
NOTE: this article assumes you are using the default Amazon DocumentDB port 27017. Adjust the configurations accordingly if you are using a non-default port.
Step 1: Create the VPC peering connection (source account)
In the VPC console choose Peering Connections → Create Peering Connection:
- VPC ID (Requester): the source VPC (where the source Amazon DocumentDB cluster lives)
- Account: select Another account
- Account ID: the target account ID
- Region: the target Amazon DocumentDB cluster's region
- VPC ID (Accepter): the target VPC ID
Choose Create peering connection.
Step 2: Accept the peering connection (target account)
Switch to the target account. In the VPC console choose Peering Connections:
- Select the pending request, then Actions → Accept Request.
- Confirm the status shows Active in both accounts before moving on.
Step 3: Enable cross-account DNS resolution (both accounts)
Amazon DocumentDB endpoints are DNS names. By default, neither VPC will resolve the other account's private hostnames to private IPs. Without this, your connection won't work.
In each account's VPC console choose Peering connections, select the peering connection from Step 1, then Actions → Edit DNS Settings:
- Source account: select Allow accepter VPC to resolve DNS of requester VPC hosts to private IP
- Target account: select Allow requester VPC to resolve DNS of accepter VPC hosts to private IP
Save changes in both. This is what lets the DMS replication instance resolve the target Amazon DocumentDB endpoint to a private IP that actually routes over the peering connection.
Step 4: Update the route tables (both accounts)
Routes allow the traffic to flow from one VPC to the other. In each account, add a route pointing the other VPC's CIDR at the peering connection.
Source account: In the VPC console choose Route tables, select the route table associated with the source Amazon DocumentDB cluster subnets, then Actions → Edit routes → Add route:
- Destination: the target VPC CIDR block
- Target: Peering Connection → select the peering connection from Step 1
Save changes.
Target account: In the VPC console choose Route tables, select the route table associated with the target Amazon DocumentDB cluster subnets, then Actions → Edit routes → Add route:
- Destination: the source VPC CIDR block
- Target: Peering Connection → select the peering connection from Step 1
Save changes.
Congratulations! The hardest part is complete!
The easy part: wiring up DMS
Now that the network path exists, configuring DMS is (almost) anticlimactic.
Step 5: Create the DMS replication instance (source account)
In the DMS console choose Provisioned instances → Create replication instance:
- VPC for IPv4: the source VPC used in the peering connection
- Replication subnet group: use or create a subnet group with the same subnets as the source Amazon DocumentDB cluster
Configure the rest to taste and choose Create replication instance.
Step 6: Security groups on the source side (source account)
On the source Amazon DocumentDB cluster security group, add an inbound rule allowing TCP 27017, Source = the DMS replication instance's security group.
On the DMS replication instance security group, add an outbound rule allowing TCP 27017, Destination = the source Amazon DocumentDB cluster's security group.
Step 7: Security group on the target side (target account)
On the target Amazon DocumentDB cluster security group, add an inbound rule allowing TCP 27017. Because this is cross-account, you can't reference the DMS instance's security group by ID here. Instead, set Source = the CIDR block of the source VPC (where both the source Amazon DocumentDB cluster and the DMS replication instance live).
This is the one that gets everyone. Within an account, you reference security groups by ID. Across accounts, that reference doesn't exist, so you fall back to a CIDR-based rule. If your target endpoint test fails with a timeout, this rule (or a missing route from Step 4) is likely the culprit.
Step 8: Create and test the source endpoint (source account)
In the DMS console choose Endpoints → Create endpoint, Endpoint type = Source endpoint, configured for the source Amazon DocumentDB cluster. Then select it, Actions → Test connection, pick the replication instance from Step 5, and Run test.
If it fails: re-check the source Amazon DocumentDB cluster security group and the DMS replication instance security group from Step 6.
Step 9: Create and test the target endpoint (source account)
In the DMS console choose Endpoints → Create endpoint, Endpoint type = Target endpoint, configured for the target Amazon DocumentDB cluster. Test it against the replication instance.
If it fails: this is your route-table + cross-account security group moment. Verify Steps 3, 4, and 7. A target test failure is most likely due to an issue with the network path.
Step 10: Create the replication task (source account)
In the DMS console choose Tasks → Create task:
- Select the source and target endpoints from Steps 8 and 9
- Select the replication instance from Step 5
- Choose your migration type: full load, CDC, or full load + CDC
- Configure table mappings, transformations, and task settings
Choose Create task and you're migrating across accounts.
When a connection test fails: the 60-second checklist
Every cross-account DMS failure I've encountered traces back to one of these. Walk them in order:
- Peering connection - confirm the peering connection status is Active in both accounts.
- DNS resolution on the peering connection - confirm it is configured in both VPCs (Step 3).
- Route tables - confirm there a route on each side pointing at the peering connection (Step 4).
- Cross-account security group - confirm the target Amazon DocumentDB security group uses a CIDR source, not a security group reference (Step 7).
- Port 27017 - confirm security groups are configured to allow inbound on the clusters and outbound on the DMS replication instance on this port.
Next steps
Once the task is running, monitor it from the DMS console. Task statistics, table statistics, and CloudWatch logs will tell you how the full load and (if enabled) CDC are progressing. When the full load completes and CDC is caught up, you can plan your application cutover to the target cluster.
Wrapping up
Cross-account Amazon DocumentDB migration with DMS isn't hard but it lives or dies on the networking, and that's exactly the part most guides gloss over. Get the peering, DNS resolution, routes, and cross-account security groups right, and DMS does the rest without complaint. Get one of them wrong, and you get a connection test that fails with a shrug.
Work through the network path once, in order, and you'll have a repeatable pattern you can hand to the next team that needs it.
If you've made it this far, come join the NoSQL Launchpad in Builder Center. That's where the AWS NoSQL specialists hang out, share what they've learned, and post cool stuff like this article.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article