Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to DocumentDB from another region

Tags:

TL;DR

DocumentDB in another region <-------- ec2 instance in another region
                               access

So AWS has launched MongoDB as a service and calls it DocumentDB. Currently the supported regions are:
1. N. Virginia
2. Ohio
3. Oregon
4. Ireland

So according to their documentation, to access the documentDB:

To interact with your Amazon DocumentDB cluster, you must launch an Amazon Elastic Compute Cloud (Amazon EC2) instance into your default VPC, in the same AWS Region where you created your Amazon DocumentDB cluster.

I did this and it works as expected.

The problem is, how do I access this from another ec2 instance on another VPC, security group and another region.

I tried to access it and this was the exception:

pymongo.errors.ServerSelectionTimeoutError: .... 
[Errno 113] No route to host

Note: The above works if I launch an ec2 instance within the same region and same security group.

Is there something I can do to whitelist the ec2 instance in another region using firewall settings?

like image 208
Adarsh Avatar asked Jan 10 '19 07:01

Adarsh


2 Answers

AWS documentdb troubleshooting guide here answers this exact question;

I solved the same issue with VPC Peering (as described in the article)

like image 169
Naor Bar Avatar answered Nov 12 '22 10:11

Naor Bar


Have you looked into vpc-peer-region-example documentation by AWS?

Seems like the architecture mentioned in (doc) is perfect fit for you. It shows how to use a combination of VPC peering and AWS PrivateLink to extend access to private services to consumer in different region (and different vpcs).

like image 44
Ankit Gupta Avatar answered Nov 12 '22 11:11

Ankit Gupta