

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# `AWSSupport-TroubleshootLambdaInternetAccess`
<a name="AWSSupport-TroubleshootLambdaInternetAccess"></a>

 **描述** 

 该`AWSSupport-TroubleshootLambdaInternetAccess`运行手册可帮助您解决在亚马逊虚拟私有云（Amazon VPC）中启动的 AWS Lambda 功能的互联网访问问题。对子网路由、安全组规则和网络访问控制列表 (ACL) 规则等资源进行审查，以确认允许出站互联网访问。

 [运行此自动化（控制台）](https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootLambdaInternetAccess) 

**文档类型**

自动化

**所有者**

Amazon

**平台**

Linux、macOS、Windows

**参数**
+ AutomationAssumeRole

  类型：字符串

  描述：（可选）允许 Systems Manager Automation 代表您执行操作 AWS Identity and Access Management (IAM) 角色的 Amazon 资源名称（ARN）。如果未指定角色，Systems Manager Automation 将使用启动此运行手册的用户的权限。
+ FunctionName

  类型：字符串

  描述：（必需）要为其排除互联网访问问题的 Lambda 函数的名称。
+ destinationIp

  类型：字符串

  描述：（必需）要与之建立出站连接的目标 IP 地址。
+ destinationPort

  类型：字符串

  默认值：443

  描述：（可选）要在其上建立出站连接的目标端口。

**所需的 IAM 权限**

`AutomationAssumeRole` 参数需要执行以下操作才能成功使用运行手册。
+  `lambda:GetFunction` 
+  `ec2:DescribeRouteTables` 
+  `ec2:DescribeNatGateways` 
+  `ec2:DescribeSecurityGroups` 
+  `ec2:DescribeNetworkAcls` 

 **文档步骤** 
+  `aws:executeScript` - 验证启动 Lambda 函数的 VPC 中各种资源的配置。
+  `aws:branch` - 根据指定的 Lambda 函数是否在 VPC 中进行分支。
+  `aws:executeScript` - 查看其中启动 Lambda 函数的子网的路由表路由，并验证是否存在到网络地址转换 (NAT) 网关和互联网网关的路由。确认 Lambda 函数不在公有子网中。
+  `aws:executeScript` - 根据为 `destinationIp` 和 `destinationPort` 参数指定的值，验证与 Lambda 函数关联的安全组是否允许出站互联网访问。
+  `aws:executeScript` - 根据为 `destinationIp` 和 `destinationPort` 参数指定的值，验证与 Lambda 函数子网关联的 ACL 规则和 NAT 网关是否允许出站互联网访问。

 **输出** 

checkVpc.vpc - Lambda 函数启动所在 VPC 的 ID。

checkvpc.Subnet-启动您 IDs 的 Lambda 函数的子网。

checkVpc.securityGroups - 与 Lambda 函数关联的安全组。

 checkNACL.NACL - 带有资源名称的分析消息。`LambdaIp` 指 Lambda 函数的弹性网络接口的私有 IP 地址。`LambdaIpRules` 对象仅对具有通往 NAT 网关的路由的子网生成。以下内容为输出示例。

```
{
   "subnet-1234567890":{
      "NACL":"acl-1234567890",
      "destinationIp_Egress":"Allowed",
      "destinationIp_Ingress":"notAllowed",
      "Analysis":"This NACL has an allow rule for Egress traffic but there is no Ingress rule. Please allow the destination IP / destionation port in Ingress rule",
      "LambdaIpRules":{
         "{LambdaIp}":{
            "Egress":"notAllowed",
            "Ingress":"notAllowed",
            "Analysis":"This is a NAT subnet NACL. It does not have ingress or egress rule allowed in it for Lambda's corresponding private ip {LambdaIp} Please allow this IP in your egress and ingress NACL rules"
         }
      }
   },
   "subnet-0987654321":{
      "NACL":"acl-0987654321",
      "destinationIp_Egress":"Allowed",
      "destinationIp_Ingress":"notAllowed",
      "Analysis":"This NACL has an allow rule for Egress traffic but there is no Ingress rule. Please allow the destination IP / destionation port in Ingress rule"
   }
}
```

checkSecurityGroups.secgrps-分析与您的 Lambda 函数关联的安全组。以下内容为输出示例。

```
{
   "sg-123456789":{
      "Status":"Allowed",
      "Analysis":"This security group has allowed destintion IP and port in its outbuond rule."
   }
}
```

checkSubnet.subnets - 对 VPC 中与 Lambda 函数关联的子网的分析。以下内容为输出示例。

```
{
   "subnet-0c4ee6cdexample15":{
      "Route":{
         "DestinationCidrBlock":"8.8.8.0/26",
         "NatGatewayId":"nat-00f0example69fdec",
         "Origin":"CreateRoute",
         "State":"active"
      },
      "Analysis":"This Route Table has an active NAT gateway path. Also, The NAT gateway is launched in public subnet",
      "RouteTable":"rtb-0b1fexample16961b"
   }
}
```