使用 NAT 网关 SSH 到在 VPC 中启动的 EB 实例

SSH in to EB instance launched in VPC with NAT Gateway

我已经使用 NAT 网关在带有 Amazon RDS (postgresql) 的 VPC 中启动了一个 Elastic Beanstalk 应用程序(因为我想通过修复 public ip 地址路由我的应用程序流量),遵循以下说明:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/vpc-rds.html

如何从本地系统通过 ssh 连接到实例?
eb ssh 显示以下错误,但我的实例可用且未终止。

ERROR: This instance does not have a Public IP address. This is possibly because the instance is terminating.

如何登录postgresql客户端?
以下命令未提示任何内容:

psql --host= --port=5432 --username= --password --dbname=ebdb

我知道它们在私有子网中,因此无法从 public 网络访问,但我想知道这种可能性。请帮忙!

您必须拥有一个可以从 VPC 外部连接到 public IP(在 public VPC 子网中)的服务器。我建议将 t2.nano 服务器设置为 bastion host

如果使用VPN,也可以修改sshops.py使用私有DNS名称。因 OS 和版本而异,但我的位于此处:

~/Library/Python/2.7/lib/python/site-packages/ebcli/operations/sshops.py

搜索PublicIpAddress(我的在第88行),改成:

ip = instance['PrivateDnsName'] #was PublicIpAddress

遗憾的是 EB CLI 没有启用 Github...否则我会提供一种通过参数来完成此操作的方法。

我还为此添加了一个方便的别名:

alias appname='eb init appname;eb ssh --region=us-east-1 appname -n'

这允许 运行 appname 1appname n,其中 n 是集群中的主机数。