

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

# `AWSSupport-TroubleshootOpenSearchRedYellowCluster`
<a name="automation-troubleshoot-opensearch-red-yellow-cluster"></a>

 **Description** 

 `AWSSupport-TroubleshootOpenSearchRedYellowCluster` 自動化 Runbook 用於識別[紅色](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/handling-errors.html#handling-errors-red-cluster-status)或[黃色](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/handling-errors.html#handling-errors-yellow-cluster-status)叢集運作狀態的原因，並引導您將叢集變更回綠色。

 **如何運作？** 

 Runbook `AWSSupport-TroubleshootOpenSearchRedYellowCluster`可協助您疑難排解紅色或黃色叢集的原因，並提供後續步驟，透過分析叢集組態和資源使用率來解決此問題。

 Runbook 會執行下列步驟：
+  針對目標網域呼叫 [DescribeDomain](https://docs.aws.amazon.com//opensearch-service/latest/APIReference/API_DescribeDomain.html) API，以取得叢集組態。
+  檢查 OpenSearch Service 網域是網際網路型 （公有） 還是 [Amazon Virtual Private Cloud (VPC)](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/vpc.html)。
+  根據叢集組態建立公有或 [Amazon VPC 型](https://docs.aws.amazon.com//lambda/latest/dg/foundation-networking.html) AWS Lambda 函數。注意：Lambda 函數包含針對叢集執行 OpenSearch Service APIs的故障診斷程式碼，以判斷叢集為何處於紅色或黃色狀態。
+  刪除 Lambda 函數。
+  顯示執行的檢查，以及解決紅色或黃色叢集問題的下一個建議步驟。

**文件類型**

 自動化

**擁有者**

Amazon

**平台**

Linux、macOS、 Windows

**參數**

**必要的 IAM 許可**

`AutomationAssumeRole` 參數需要下列動作才能成功使用 Runbook。
+ `cloudformation:CreateStack`
+ `cloudformation:DescribeStacks`
+ `cloudformation:DescribeStackEvents`
+ `cloudformation:DeleteStack`
+ `lambda:CreateFunction`
+ `lambda:DeleteFunction`
+ `lambda:InvokeFunction`
+ `lambda:GetFunction`
+ `es:DescribeDomain`
+ `es:DescribeDomainConfig`
+ `ec2:DescribeSecurityGroups`
+ `ec2:DescribeSubnets`
+ `ec2:DescribeVpcs`
+ `ec2:DescribeNetworkInterfaces`
+ `ec2:CreateNetworkInterface`
+ `ec2:DeleteNetworkInterface`
+ `ec2:DescribeInstances`
+ `ec2:AttachNetworkInterface`
+ `cloudwatch:GetMetricData`
+ `iam:PassRole`

`LambdaExecutionRole` 參數需要下列動作才能成功使用 Runbook：
+ `es:ESHttpGet`
+ `ec2:CreateNetworkInterface`
+ `ec2:DescribeNetworkInterfaces`
+ `ec2:DeleteNetworkInterface`

`LambdaExecutionRole` 政策概觀：

 以下是 Lambda 函數執行角色 (AWS Identity and Access Management (IAM) 角色） 的範例，授予函數存取此 Runbook 所需 AWS 服務和資源的許可。如需更多詳細資訊，請參閱 [Lambda 執行角色](https://docs.aws.amazon.com//lambda/latest/dg/lambda-intro-execution-role.html)。

**注意**  
 `ec2:DeleteNetworkInterface` 只有當您的 OpenSearch Service 叢集是以 [Amazon VPC 為基礎](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/vpc.html)，以允許 Lambda `ec2:DescribeNetworkInterfaces`函數建立和管理 Amazon VPC 網路介面時，才需要 `ec2:CreateNetworkInterface`、 和 。如需詳細資訊，請參閱[將傳出聯網連接到 Amazon VPC 和 Lambda 執行角色中的資源](https://docs.aws.amazon.com//lambda/latest/dg/configuration-vpc.html#vpc-permissions)。 [https://docs.aws.amazon.com//lambda/latest/dg/lambda-intro-execution-role.html](https://docs.aws.amazon.com//lambda/latest/dg/lambda-intro-execution-role.html)

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "es:ESHttpGet",
            "Resource": [
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/",
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/_cluster/health",
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/_cat/indices",
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/_cat/allocation",
                "arn:aws:es:us-east-1:111122223333:domain/domain-name/_cluster/allocation/explain"
            ]
        },
        {
            "Condition": {
                "ArnLikeIfExists": {
                    "ec2:Vpc": "arn:aws:ec2:us-east-1:111122223333:vpc/vpc_id"
                }
            },
            "Action": [
                "ec2:DeleteNetworkInterface",
                "ec2:CreateNetworkInterface",
                "ec2:DescribeNetworkInterfaces",
                "ec2:UnassignPrivateIpAddresses",
                "ec2:AssignPrivateIpAddresses"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
```

------

 **指示** 

請依照下列步驟設定自動化：

1. 導覽至主控台中的 [AWSSupport-TroubleshootOpenSearchRedYellowCluster](https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootOpenSearchRedYellowCluster/description) AWS Systems Manager 。

1. 選擇 Execute automation (執行自動化)。

1. 針對輸入參數，輸入下列項目：
   + **AutomationAssumeRole （選用）：**

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

     Lambda 用來簽署 Amazon OpenSearch Service 叢集請求的 IAM 角色 ARN。
   + **DomainName （必要）：**

     具有紅色或黃色叢集運作狀態的 OpenSearch Service 網域名稱。
   + **UtilizationThreshold （選用）：**

     用於比較 CPUUtilization 和 JVMMemoryPressure 指標的使用率閾值百分比。預設值為 80。  
![\[Input parameters form for AWS Systems Manager Automation with IAM roles and domain settings.\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-red-yellow-cluster_input_paramters.png)

1. 如果您已在 OpenSearch Service 叢集上啟用[精細存取控制](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/fgac.html)，請確定`LambdaExecutionRole`角色 arn 已映射至至少具有 `cluster_monitor` 許可的角色。  
![\[叢集 permissions section showing cluster_monitor permission granted.\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-red-yellow-cluster_permissions.png)  
![\[Backend roles interface showing an AWSIAM role for Lambda execution and options to remove or add roles.\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-red-yellow-cluster_backend_roles.png)

1. 選取執行。

1. 自動化會啟動。

1. 自動化 Runbook 會執行下列步驟：
   + **GetClusterConfiguration：**

     擷取 OpenSearch Service 叢集組態。
   + **CreateAWSLambdaFunctionStack：**

     使用 在帳戶中建立臨時 Lambda 函數 CloudFormation。Lambda 函數用於執行 OpenSearch Service APIs。
   + **WaitForAWSLambdaFunctionStack：**

     等待 CloudFormation 堆疊完成。
   + **GetClusterMetricsFromCloudWatch：**

     取得 Amazon CloudWatch ClusterStatus、CPUUtilization 和 JVMMemoryPressure OpenSearch Service 叢集相關指標及其建立日期。
   + **RunOpenSearchAPIs：**

     使用 Lambda 函數呼叫 OpenSearch Service APIs，並分析叢集指標資料，以診斷紅色或黃色叢集狀態的原因。
   + **DeleteAWSLambdaFunctionStack：**

     刪除您帳戶中此自動化建立的 Lambda 函數。

1. 完成後，請檢閱輸出區段以取得執行的詳細結果。
   + **RootCause：**

     提供叢集運作狀態為紅色或黃色的已識別原因概觀。
   + **IssueDescription：**

     提供叢集為何處於紅色或黃色狀態的詳細資訊，以及讓叢集回到綠色狀態的可能步驟。

 **參考** 

Systems Manager Automation
+ [執行此自動化 （主控台）](https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootOpenSearchRedYellowCluster)
+ [執行自動化](https://docs.aws.amazon.com//systems-manager/latest/userguide/automation-working-executing.html)
+ [設定 自動化](https://docs.aws.amazon.com//systems-manager/latest/userguide/automation-setup.html)
+ [支援自動化工作流程登陸頁面](https://aws.amazon.com/premiumsupport/technology/saw/)

AWS 服務文件
+ 如需詳細資訊，請參閱[疑難排解 Amazon OpenSearch Service](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/handling-errors.html) 