Elastic Beanstalk 和 EC2 实例连接:无法连接

Elastic Beanstalk & EC2 Instance Connect: Can't connect

我从 Visual Studio 创建了一个 Elastic Beanstalk 环境,需要登录才能为底层 ec2 虚拟机提供服务。

我没有服务器的凭据,所以我想使用 EC2 Instance Connect

当我点击连接时,我收到一条错误信息:

We were unable to connect to your instance. Make sure that your instance’s network settings are configured correctly for EC2 Instance Connect. For more information, see Task 1: Configure network access to an instance.

按照link,我找到了说明:

  • Ensure that the security group associated with your instance allows inbound SSH traffic on port 22 from your IP address or from your network.
  • (Amazon EC2 console browser-based client) We recommend that your instance allows inbound SSH traffic from the recommended IP block published for the service. Use the EC2_INSTANCE_CONNECT filter for the service parameter to get the IP address ranges in the EC2 Instance Connect subset.

如何通过 EC2 Instance Connect 连接到 EC2 底层的 Elastic Beanstalk?

我试过的:

我创建了一个包含我的客户端 IP 地址的新安全组,但是没有用。这是有道理的,因为它是控制台中的 EC2 Instance Connect 应用程序 运行 建立 SSH 连接,而不是我的本地计算机。

还查看了 ip 范围 json 文件 (https://ip-ranges.amazonaws.com/ip-ranges.json),但不确定如何处理它。

通常比使用 EC2 Instance Connect 更好的方法是通过 SSM System Manager. It does not require opening any inbound ports. Instead you should add/modify your install role to allow SSM 来工作。此外,与 EC2 Instance Connect 不同,您可以使用常规 IAM 权限控制对实例的访问。

通过 SSM 的连接与 EC2 Instance Connect 位于 AWS 控制台的相同菜单中。因此,一旦您设置了您的实例角色,等待几分钟让实例注册到 SSM,一旦发生这种情况,您应该能够使用 SSM 系统管理器从控制台连接到您的实例。

关于 EC2 Instance Connect IP 范围。我不知道发布的哪个范围仅适用于 EC2 Instance Connect。您可能必须 按区域 过滤它,然后找到一个有效的。在更坏的情况下,它的尝试和观察方法。

我误解了Set up EC2 Instance Connect instructions. This support article had clearer instructions: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-connect-troubleshooting/

Browser-based SSH connections require that your instance's security group inbound rules allow EC2 Instance Connect access to SSH on TCP port 22.

关键是找到 EC2 Instance Connect 的 IP,然后创建 用于将该 IP 地址列入白名单的安全组。

可以使用 Get-AWSPublicIpAddressRange(或 curl)通过 PowerShell 检索 EC2 实例连接 IP。对于 us-west-2:

> Get-AWSPublicIpAddressRange -Region us-west-2 -ServiceKey EC2_INSTANCE_CONNECT | select IpPrefix


IpPrefix
--------
18.237.140.160/29

将我的安全组配置为使用该源后,我就可以连接了。