

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

 **Description** 

 `AWSSupport-TroubleshootLambdaInternetAccess` Runbook 可協助您疑難排解在 Amazon Virtual Private Cloud (Amazon VPC) 中啟動之 AWS Lambda 函數的網際網路存取問題。會檢閱子網路路由、安全群組規則和網路存取控制清單 (ACL) 規則等資源，以確認允許傳出網際網路存取。

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

**文件類型**

 自動化

**擁有者**

Amazon

**平台**

Linux、macOS、 Windows

**參數**
+ AutomationAssumeRole

  類型：字串

  描述：（選用） 允許 Systems Manager Automation 代表您執行動作的 (IAM) 角色的 AWS Identity and Access Management Amazon Resource Name (ARN)。如果未指定角色，Systems Manager Automation 會使用啟動此 Runbook 之使用者的許可。
+ FunctionName

  類型：字串

  描述：（必要） 您要疑難排解網際網路存取的 Lambda 函數名稱。
+ destinationIp

  類型：字串

  描述：（必要） 您要建立傳出連線的目的地 IP 地址。
+ destinationPort

  類型：字串

  預設：443

  描述：（選用） 您要建立傳出連線的目的地連接埠。

**必要的 IAM 許可**

`AutomationAssumeRole` 參數需要下列動作才能成功使用 Runbook。
+  `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` - 驗證與 Lambda 函數相關聯的安全群組，允許根據為 `destinationIp`和 `destinationPort` 參數指定的值進行傳出網際網路存取。
+  `aws:executeScript` - 驗證與 Lambda 函數子網路相關聯的 ACL 規則，且 NAT 閘道允許根據 `destinationIp`和 `destinationPort` 參數指定的值進行傳出網際網路存取。

 **輸出** 

checkVpc.vpc - 啟動 Lambda 函數的 VPC ID。

checkVpc.subnet - 啟動 Lambda 函數的子網路 IDs。

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 - 分析與 Lambda 函數相關聯的 VPC 中的子網路。下列內容是輸出的範例。

```
{
   "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"
   }
}
```