从另一个区域连接到 DocumentDB
Connect to DocumentDB from another region
TL;DR
DocumentDB in another region <-------- ec2 instance in another region
access
因此 AWS 推出了 MongoDB 作为一项服务并将其称为 DocumentDB。
目前支持的地区有:
1. 北弗吉尼亚
2. 俄亥俄
3. 俄勒冈州
4. 爱尔兰
所以根据他们documentation,访问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.
我这样做了,它按预期工作。
问题是,我如何从另一个 VPC、安全组和另一个区域上的另一个 ec2 实例访问它。
我试图访问它,但这是个例外:
pymongo.errors.ServerSelectionTimeoutError: ....
[Errno 113] No route to host
注意:如果我在同一区域和同一安全组中启动 ec2 实例,以上方法有效。
我可以做些什么来使用防火墙设置将另一个区域的 ec2 实例列入白名单吗?
您是否查看过 AWS 的 vpc-peer-region-example 文档?
(doc) 中提到的架构似乎非常适合您。它展示了如何结合使用 VPC 对等互连和 AWS PrivateLink 来将对私有服务的访问扩展到不同区域(和不同 vpc)的消费者。
由于Document-DB cluster和DB-instance默认配置为特定区域,因此可以只能从 VPC 内的 ec2-instances 访问。
或者你的本地机器可以访问也在同一地区的 PVC。
注意:仅当启用了安全组才能访问您的机器 IP。
但是我们可以使用端口转发技术,也就是 ssh 隧道 来使来自任何地区的任何用户都可以访问您的数据库,它仍然需要一个 ec2 -instance or bastion instance 和 运行.
按照文档使用亚马逊会话管理器创建代理服务器
https://aws.amazon.com/premiumsupport/knowledge-center/systems-manager-ssh-vpc-resources/
从您的机器创建隧道
ssh -i ec2-keypair-private.pem ec2-user-name@ec2-public-dns-name -N -L 27017:document-db-cluster-name:27017
使用Mongo shell 在本地登录您的机器
mongo --ssl --host localhost:27017 --sslCAFile rds-combined-ca-bundle.pem --username username --password password
注意:您的 Document-DB 集群应该允许您正在使用的 ec2 实例访问它,我们可以从与该集群关联的安全组中修改它。
希望对您有所帮助!
AWS documentdb 故障排除指南here 回答了这个问题;
我用 VPC Peering 解决了同样的问题(如文章中所述)
TL;DR
DocumentDB in another region <-------- ec2 instance in another region
access
因此 AWS 推出了 MongoDB 作为一项服务并将其称为 DocumentDB。
目前支持的地区有:
1. 北弗吉尼亚
2. 俄亥俄
3. 俄勒冈州
4. 爱尔兰
所以根据他们documentation,访问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.
我这样做了,它按预期工作。
问题是,我如何从另一个 VPC、安全组和另一个区域上的另一个 ec2 实例访问它。
我试图访问它,但这是个例外:
pymongo.errors.ServerSelectionTimeoutError: ....
[Errno 113] No route to host
注意:如果我在同一区域和同一安全组中启动 ec2 实例,以上方法有效。
我可以做些什么来使用防火墙设置将另一个区域的 ec2 实例列入白名单吗?
您是否查看过 AWS 的 vpc-peer-region-example 文档?
(doc) 中提到的架构似乎非常适合您。它展示了如何结合使用 VPC 对等互连和 AWS PrivateLink 来将对私有服务的访问扩展到不同区域(和不同 vpc)的消费者。
由于Document-DB cluster和DB-instance默认配置为特定区域,因此可以只能从 VPC 内的 ec2-instances 访问。 或者你的本地机器可以访问也在同一地区的 PVC。
注意:仅当启用了安全组才能访问您的机器 IP。
但是我们可以使用端口转发技术,也就是 ssh 隧道 来使来自任何地区的任何用户都可以访问您的数据库,它仍然需要一个 ec2 -instance or bastion instance 和 运行.
按照文档使用亚马逊会话管理器创建代理服务器 https://aws.amazon.com/premiumsupport/knowledge-center/systems-manager-ssh-vpc-resources/
从您的机器创建隧道
ssh -i ec2-keypair-private.pem ec2-user-name@ec2-public-dns-name -N -L 27017:document-db-cluster-name:27017
使用Mongo shell 在本地登录您的机器
mongo --ssl --host localhost:27017 --sslCAFile rds-combined-ca-bundle.pem --username username --password password
注意:您的 Document-DB 集群应该允许您正在使用的 ec2 实例访问它,我们可以从与该集群关联的安全组中修改它。 希望对您有所帮助!
AWS documentdb 故障排除指南here 回答了这个问题;
我用 VPC Peering 解决了同样的问题(如文章中所述)