如何使用 Robo 3T 连接到 AWS Documentdb?

How can I connect to AWS Documentdb with Robo 3T?

使用最新的Robo 3T和AWS提供的命令行

mongodb://<dbname>:<insertYourPassword>@example-db.cluster-c2e1234stuff0e.eu-west-2.docdb.amazonaws.com:27017

我得到这个错误:

Reason: SSL tunnel failure: Network is unreachable or SSL connection rejected by server. Reason: Connect failed

我也尝试过 THIS 演练,但并不开心。

我了解到可以通过 SSH 连接到同一 VPC 上的 EC2 实例并以这种方式访问​​ documentdb,但理想情况下我想直接访问它而不是为额外的 EC2 实例付费。如果我说得对?

我也尝试通过 Mongo shell 并得到以下响应:

Error: couldn't connect to server example-db.cluster-c2eblahblaho0e.eu-west-2.docdb.amazonaws.com:27017, connection attempt failed: NetworkTimeout: Error connecting to example-db.cluster-c2eblahblaho0e.eu-west-2.docdb.amazonaws.com:27017 (<IP address>) :: caused by :: Socket operation timed out :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6
exception: connect failed

我怀疑正在发生的事情是您在与 DocumentDB 集群相同的 VPC 中没有 EC2 实例,或者无法从您的笔记本电脑访问该 EC2 实例。我首先使用 SSH 连接到 EC2 实例以建立连接,然后使用该 EC2 实例从 Robo3T 进行 SSH 代理。

就上下文而言,EC2 实例或部署在同一 VPC 中的其他 AWS 服务可以直接访问部署在 VPC 中的 Amazon DocumentDB 集群。此外,Amazon DocumentDB 可以通过同一区域或其他区域的不同 VPC 中的 EC2 实例或其他 AWS 服务通过 VPC 对等访问。

在 VPC 内部署集群的优势在于 VPC 为 Internet 提供了强大的网络边界。从笔记本电脑连接到 DocumentDB 的一种常见方法是在与 DocumentDB 集群相同的 VPC 中创建一个 EC2 实例,并通过该 EC2 实例到您的集群的 SSH 隧道:https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html

为了最大限度地降低本地开发成本,请从最小的 EC2 实例开始,并在不使用集群时利用 start/stop 功能。

同样可以用 DocumentDB 来完成。在开发过程中,您可以通过在不再需要时停止集群来节省实例成本:https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-stop-start.html

另一种方法是利用 AWS Cloud9:https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-with-cloud9.html。此解决方案仍然需要与您的 Amazon 文档位于同一 VPC 中的 EC2 实例。这个解决方案的用处在于,Cloud9 提供了一种机制,如果 EC2 实例闲置 30 分钟,它会自动关闭,以帮助节省成本。