简体   繁体   English

Lambda Function 中的连接超时错误

[英]Connection timed out error in Lambda Function

I am trying to SSH all the ec2 instances in AWS account through lambda function.我正在尝试通过 lambda function 对 AWS 账户中的所有 ec2 实例进行 SSH。

c.connect( hostname = each_in.private_ip_address, username = 'pcs_user', pkey = k ) c.connect(主机名 = each_in.private_ip_address,用户名 = 'pcs_user',pkey = k)

But I'm getting an error like this.但是我遇到了这样的错误。 I have used AWSLambdaVPCAccessExecutionRole to IAM role.我已将 AWSLambdaVPCAccessExecutionRole 用于 IAM 角色。

Response:
{
  "errorMessage": "[Errno 110] Connection timed out",
  "errorType": "TimeoutError",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 30, in lambda_handler\n    c.connect( hostname = each_in.private_ip_address, username = 'pcs_us', pkey = k )\n",
    "  File \"/opt/python/paramiko/client.py\", line 349, in connect\n    retry_on_signal(lambda: sock.connect(addr))\n",
    "  File \"/opt/python/paramiko/util.py\", line 283, in retry_on_signal\n    return function()\n",
    "  File \"/opt/python/paramiko/client.py\", line 349, in <lambda>\n    retry_on_signal(lambda: sock.connect(addr))\n"
  ]
}

This looks like the Lambda is unable to connect to your EC2 instances due to a security group rule blocking access.由于安全组规则阻止访问,Lambda 似乎无法连接到您的 EC2 实例。

If you are trying to connect to EC2 instances in your account you should add your Lambda to your VPC by attaching it via VPC configuration, it should be added into private subnets.如果您尝试连接到您账户中的 EC2 实例,您应该通过 VPC 配置将Lambda 添加到您的 VPC ,它应该添加到私有子网中。

Once your Lambdas are added to your VPC, whitelist in your security group of the instances allowing the IP range(s) of the subnet(s) in which your Lambda resides.将您的 Lambda 添加到您的 VPC 后,在您的实例的安全组中列入白名单,允许 Lambda 所在子网的 IP 范围。

By doing this you are stopping any access from traversing the public internet.通过这样做,您将阻止任何访问通过公共互联网。 Ensure your Lambda connects to any VPCs via their private IP address.确保您的 Lambda 通过其私有 IP 地址连接到任何 VPC。 For any instances outside your VPC you will need to use peering either via Transit Gateway or a peering connection .对于您的 VPC 之外的任何实例,您将需要通过Transit Gateway或对等连接使用对等连接

If you cannot have your Lambda in a VPC then you will need to maintain a whitelist in the security group of each instance to whitelist the Lambda public range from the ip-ranges.json file.如果您不能将 Lambda 放在 VPC 中,那么您需要在每个实例的安全组中维护一个白名单,以将ip-ranges.json文件中的 Lambda 公共范围列入白名单。 This must be for the range of the Lambda service in the region it has been deployed to.这必须针对已部署到的区域中的 Lambda 服务的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM