

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

# `AWSSupport-TroubleshootOpenSearchHighCPU`
<a name="automation-troubleshoot-opensearch-high-cpu"></a>

 **描述** 

 该`AWSSupport-TroubleshootOpenSearchHighCPU`运行手册提供了一种自动解决方案，用于从 Amazon S OpenSearch ervice 域收集诊断数据，以解决[高 CPU](https://repost.aws/knowledge-center/opensearch-troubleshoot-high-cpu) 问题。

 **如何工作？** 

 该`AWSSupport-TroubleshootOpenSearchHighCPU`运行手册有助于解决亚马逊 OpenSearch 服务域中 CPU 使用率过高的问题。

 运行手册执行以下步骤：
+  对提供的亚马逊 OpenSearch 服务域运行 [DescribeDomain](https://docs.aws.amazon.com//opensearch-service/latest/APIReference/API_DescribeDomain.html)API 以获取集群元数据。
+  检查亚马逊 OpenSearch 服务域是公共域还是基于 Amazon VPC 的域，并在的帮助下创建公共函数或基于 A [mazon V](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/vpc.html) AWS Lambda PC 的 CloudFormation函数。
+  Lambda 函数从亚马逊 OpenSearch 服务域中获取诊断数据。
+  使用 AWS Step Functions 状态机协调多个 Lambda 函数执行，以收集更全面的数据。
+  默认情况下，将收集的数据存储在 Amazon CloudWatch 日志组中 24 小时。
+  删除已创建的资源，但 CloudWatch 日志组除外。

**文档类型**

自动化

**所有者**

Amazon

**平台**

Linux、macOS、Windows

**参数**

**所需的 IAM 权限**

`AutomationAssumeRole` 参数需要执行以下操作才能成功使用运行手册。
+ `cloudformation:CreateStack`
+ `cloudformation:CreateStack`
+ `cloudformation:DescribeStacks`
+ `cloudformation:DescribeStackEvents`
+ `cloudformation:DeleteStack`
+ `lambda:CreateFunction`
+ `lambda:DeleteFunction`
+ `lambda:InvokeFunction`
+ `lambda:GetFunction`
+ `lambda:TagResource`
+ `es:DescribeDomain`
+ `ec2:DescribeSecurityGroups`
+ `ec2:DescribeSubnets`
+ `ec2:DescribeVpcs`
+ `ec2:DescribeNetworkInterfaces`
+ `ec2:CreateNetworkInterface`
+ `ec2:DescribeInstances`
+ `ec2:AttachNetworkInterface`
+ `ec2:DeleteNetworkInterface`
+ `logs:CreateLogGroup`
+ `logs:PutRetentionPolicy`
+ `logs:TagResource`
+ `states:CreateStateMachine`
+ `states:DeleteStateMachine`
+ `states:StartExecution`
+ `states:TagResource`
+ `states:DescribeStateMachine`
+ `states:DescribeExecution`
+ `iam:PassRole`
+ `iam:CreateRole`
+ `iam:DeleteRole`
+ `iam:GetRole`
+ `iam:PutRolePolicy`
+ `iam:DeleteRolePolicy`
+ `ssm:DescribeAutomationExecutions`
+ `ssm:GetAutomationExecution`

**注意**  
 `iam:CreateRole`、、`iam:DeleteRole``iam:GetRole``iam:PutRolePolicy``iam:PutRolePolicy`、和仅`iam:DeleteRolePolicy`在您未使用现有 IAM 角色作为**LambdaInvocationRoleForStepFunctions**参数时才是必需的

该`LambdaExecutionRole`参数需要以下操作才能成功使用运行手册：
+ `es:ESHttpGet`
+ `ec2:CreateNetworkInterface`
+ `ec2:DescribeNetworkInterfaces`
+ `ec2:DeleteNetworkInterface`
+ `logs:CreateLogStream`
+ `logs:PutLogEvents`

Lambda 执行角色向该函数授予访问本运行手册所需的 AWS 服务和资源的权限。有关更多信息，请参阅 [Lambda 执行角色](https://docs.aws.amazon.com//lambda/latest/dg/lambda-intro-execution-role.html)。

**注意**  
 只有当`ec2:DescribeNetworkInterfaces`您的 OpenSearch 服务集群[基于 Amazon VPC](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/vpc.html) 时，才需要`ec2:CreateNetworkInterface`、和`ec2:DeleteNetworkInterface`，以允许 Lambda 函数创建和管理 Amazon VPC 网络接口。有关更多信息，请参阅[将出站联网连接到 Amazon VPC 和 [Lambda 执行](https://docs.aws.amazon.com//lambda/latest/dg/lambda-intro-execution-role.html)角色中的资源](https://docs.aws.amazon.com//lambda/latest/dg/configuration-vpc.html#vpc-permissions)。

`LambdaInvocationRoleForStepFunctions`参数授予 AWS Step Functions 状态机调用 Lambda 函数的权限。以下是一个 IAM 策略示例，该策略授予 Step Functions 调用从服务域获取诊断数据的 Lambda 函数的 OpenSearch 权限。有关更多信息，请参阅 AWS Step Functions 开发人员指南中的[创建状态机 IAM 角色](https://docs.aws.amazon.com/step-functions/latest/dg/procedure-create-iam-role.html)。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "lambda:InvokeFunction",
            "Resource": [
                "arn:aws:lambda:us-east-1:111122223333:function:AWSSupport-HighCPU-*"
            ]
        }
    ]
}
```

------

 **说明** 

按照这些步骤对自动化进行配置：

1. 导航到 AWS Systems Manager 控制台[AWSSupport-TroubleshootOpenSearchHighCPU](https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootOpenSearchHighCPU/description)中的。

1. 选择 Execute automation（执行自动化）。

1. 要输入参数，请输入以下内容：
   + **AutomationAssumeRole （可选）：**

     允许 Systems Manager Automation 代表您执行操作的 AWS Identity and Access Management (IAM) 角色的亚马逊资源名称 (ARN)。如果未指定角色，Systems Manager Automation 将使用启动此运行手册的用户的权限。
   + **DomainName （必填）：**

     您要针对高 CPU 问题进行故障排除的 Amazon OpenSearch 服务域的名称。
   + **LambdaExecutionRoleForOpenSearch（必填）：**

     要附加到 Lambda 函数的 IAM 角色的 ARN。Lambda 函数使用此角色的证书签署对亚马逊 OpenSearch 服务域的请求。如果在 Amazon Ser OpenSearch vice 域上启用了精细访问控制，则必须将此角色映射到至少具有 “cluster\$1monitor” 权限的 OpenSearch 服务控制面板后端角色。
   + **LambdaInvocationRoleForStepFunctions（可选）：**

     （可选）要附加到 Step Functions 工作流程的 IAM 角色的 ARN。状态机使用此角色的证书来调用从服务域获取诊断数据的 Lambda 函数。 OpenSearch 如果未指定任何角色，则此自动化将在您的账户中为 Step Functions 创建一个 IAM 角色。
   + **DataRetentionDays （可选）：**

     保留从 Amazon OpenSearch 服务域收集的诊断数据的天数。默认情况下，数据保留 24 小时（一天）。您可以选择将数据最多保留 30 天。
   + **NumberOfDataSamples （可选）：**

     要从 Amazon OpenSearch 服务域中收集的数据样本数量。默认情况下，会收集 5 个数据样本。您最多可以收集 10 个样本，并且将为每个样本集合调用 Lambda 函数。

1. 如果您已在 S OpenSearch ervice 集群上启用了[精细访问控制](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_cn/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-high-cpu_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_cn/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-high-cpu_backend_roles.png)

1. 选择执行。

1. 自动化启动。

1. 自动化运行手册执行以下步骤：
   + **检查并发性：**

     确保只有一次针对指定的 Amazon S OpenSearch ervice 域名执行此操作手册。如果 runbook 发现另一次针对相同域名的执行，则会返回错误并结束。
   + **getDomainConfig:**

     获取目标 OpenSearch 服务域的配置详细信息。
   + **配置资源：**

     使用配置用于数据收集的资源 CloudFormation。
   + **waitForStack创作：**

     等待 CloudFormation 堆栈完成。
   + **describeStackResources:**

     描述 CloudFormation 堆栈并获取状态机的 ARN。
   + **runStateMachine:**

     通过运行 Step Functions 状态机来调用数据收集器 Lambda 函数一次或多次。
   + **describeErrorsFromStackEvents:**

     描述 CloudFormation 堆栈中的错误是否存在错误。
   + **unstageOpenSearch高CPUAutomation：**

     删除`AWSSupport-TroubleshootOpenSearchHighCPU` CloudFormation 堆栈。
   + **describeErrorsFromStackDeletion:**

     描述删除 CloudFormation 堆栈时遇到的错误。
   + **最终状态：**

     返回`AWSSupport-TroubleshootOpenSearchHighCPU`运行手册的最终输出。

1. 完成后，查看“输出”部分以了解执行的详细结果。
   + **最终状态。 FinalOutput**:

     提供存储诊断数据的 CloudWatch 日志组。  
![\[Output message indicating hot thread data collection completed with log group details.\]](http://docs.aws.amazon.com/zh_cn/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-opensearch-high-cpu_outputs.png)

 **参考** 

Systems Manager Automation
+ [运行此自动化（控制台）](https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootOpenSearchHighCPU)
+ [运行自动化](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 服务疑难解答](https://docs.aws.amazon.com//opensearch-service/latest/developerguide/handling-errors.html)