

# AWS WA Tool 中的剖析格式规范
<a name="lenses-format-specification"></a>

剖析是使用特定的 JSON 格式定义的。开始创建自定义剖析时，可以选择下载模板 JSON 文件。您可以使用此文件作为自定义剖析的基础，因为它定义了支柱、问题、最佳实践和改进计划的基本结构。

## 剖析部分
<a name="lenses-format-lens"></a>

本部分定义了自定义剖析本身的属性。这是它的名称和描述。
+ `schemaVersion`：要使用的自定义剖析模式的版本。由模板设置，请勿更改。
+ `name`: 剖析的名称。名称最多可以有 128 个字符。
+ `description`：剖析的文本描述。选择剖析以在创建工作负载期间添加或选择剖析以稍后应用于现有工作负载时，会显示此文本。描述长度最多为 2048 个字符。

```
    "schemaVersion": "2021-11-01",
    "name": "Company Policy ABC",
    "description": "This lens provides a set of specific questions to assess compliance with company policy ABC-2021 as revised on 2021/09/01.",
```

## 支柱部分
<a name="lenses-format-pillars"></a>

本部分定义了与自定义剖析相关的支柱。您可以将您的问题映射到 AWS Well-Architected Framework 的支柱和/或定义自己的支柱。

您最多可以在自定义剖析中定义 10 个支柱。
+ `id`: 支柱的 ID。ID 可以包含 3 到 128 个字符，并且仅包含字母数字和下划线（“\$1”）字符。支柱中使用的 ID 必须是唯一的。

  将您的问题映射到框架的支柱时，请使用以下 ID：
  + `operationalExcellence`
  + `security`
  + `reliability`
  + `performance`
  + `costOptimization`
  + `sustainability`
+ `name`：支柱的名称。名称最多可以有 128 个字符。

```
     "pillars": [
        {
            "id": "company_Privacy",
            "name": "Privacy Excellence",
            .
            .
            .
        },
        {
            "id": "company_Security",
            "name": "Security",
            .
            .
            .
        }
     ]
```

## 问题部分
<a name="lenses-format-questions"></a>

本部分定义了与支柱相关的问题。

您最多可以为自定义剖析中的一个支柱定义 20 个问题。
+ `id`：问题的 ID。ID 可以包含 3 到 128 个字符，并且仅包含字母数字和下划线（“\$1”）字符。问题中使用的 ID 必须是唯一的。
+ `title`：问题的标题。标题最多可以有 128 个字符。
+ `description`：更详细地描述了问题。描述长度最多为 2048 个字符。
+ `helpfulResource displayText`：可选。提供有关问题的有用信息的文本。文本最多可以有 2048 个字符。如果指定了 `helpfulResource url`，则必须指定。
+ `helpfulResource url`：可选。更详细地解释问题的 URL 资源。URL 必须以 `http://` 或 `https://` 开头。

**注意**  
 将自定义剖析工作负载同步到 Jira 时，“questions”部分会同时显示问题的“id”和“title”。  
 Jira 工单中使用的格式是 `[ QuestionID ] QuestionTitle`。

```
"questions": [
    {
        "id": "privacy01",
        "title": "How do you ensure HR conversations are private?",
        "description": "Career and benefits discussions should occur on secure channels only and be audited regularly for compliance.",
        "helpfulResource": {
            "displayText": "This is helpful text for the first question",
            "url": "https://example.com/poptquest01_help.html"
        },
        .
        .
        .
    },
    {
        "id": "privacy02",
        "title": "Is your team following the company privacy policy?",
        "description": "Our company requires customers to opt-in to data use and does not disclose customer data to third parties either individually or in aggregate.",
        "helpfulResource": {
            "displayText": "This is helpful text for the second question",
            "url": "https://example.com/poptquest02_help.html"
        },
        .
        .
        .
    }
]
```

## 选项部分
<a name="lenses-format-choices"></a>

本部分定义了与问题相关的选项。

您最多可以为自定义剖析中的一个问题定义 15 个选项。
+ `id`：选项的 ID。ID 可以包含 3 到 128 个字符，并且仅包含字母数字和下划线（“\$1”）字符。必须为问题中的每个选项指定唯一的 ID。添加后缀为 `_no` 的选项将作为问题的 `None of these` 选项。
+ `title`：选项的标题。标题最多可以有 128 个字符。
+ `helpfulResource displayText`：可选。提供有关选项的有用信息的文本。文本最多可以有 2048 个字符。如果指定了 `helpfulResource url`，则必须包含。
+ `helpfulResource url`：可选。更详细地解释选项的 URL 资源。URL 必须以 `http://` 或 `https://` 开头。
+ `improvementPlan displayText`：描述如何改进选项的文本。文本最多可以有 2048 个字符。除 `improvementPlan` 选项外，每个选项都必须有 `None of these`。
+ `improvementPlan url`：可选。可以帮助改进的 URL 资源。URL 必须以 `http://` 或 `https://` 开头。
+ `additionalResources type`：可选。额外资源的类型。值可以是 `HELPFUL_RESOURCE` 或 `IMPROVEMENT_PLAN`。
+ `additionalResources content`：可选。为其它资源指定 `displayText` 和 `url` 值。最多可以为一个选项指定五个额外的有用资源以及五个额外的改进计划项目。
  + `displayText`：可选。描述有用资源或改进计划的文本。文本最多可以有 2048 个字符。如果指定了 `url`，则必须包含。
  + `url`：可选。有用资源或改进计划的 URL 资源。URL 必须以 `http://` 或 `https://` 开头。

**注意**  
 将自定义剖析工作负载同步到 Jira 时，“choices”部分会显示问题和选择的“id”，以及选择的“title”。  
 使用的格式是 `[ QuestionID | ChoiceID ] ChoiceTitle`。

```
    "choices": [
         {
             "id": "choice_1",
             "title": "Option 1",
             "helpfulResource": {
                 "displayText": "This is helpful text for the first choice",
                 "url": "https://example.com/popt01_help.html"
             },
             "improvementPlan": {
                 "displayText": "This is text that will be shown for improvement of this choice.",
                 "url": "https://example.com/popt01_iplan.html"
             }
         },
         {
             "id": "choice_2",
             "title": "Option 2",
             "helpfulResource": {
                 "displayText": "This is helpful text for the second choice",
                 "url": "https://example.com/hr_manual_CORP_1.pdf"
             },
             "improvementPlan": {
                 "displayText": "This is text that will be shown for improvement of this choice.",
                 "url": "https://example.com/popt02_iplan_01.html"
             },
             "additionalResources":[
                {
                  "type": "HELPFUL_RESOURCE",
                  "content": [
                    {
                      "displayText": "This is the second set of helpful text for this choice.",
                      "url": "https://example.com/hr_manual_country.html"
                    },
                    {
                      "displayText": "This is the third set of helpful text for this choice.",
                      "url": "https://example.com/hr_manual_city.html"
                    }
                  ]
                },
                {
                  "type": "IMPROVEMENT_PLAN",
                  "content": [
                    {
                      "displayText": "This is additional text that will be shown for improvement of this choice.",
                      "url": "https://example.com/popt02_iplan_02.html"
                    },
                    {
                      "displayText": "This is the third piece of improvement plan text.",
                      "url": "https://example.com/popt02_iplan_03.html"
                    }
                    {
                      "displayText": "This is the fourth piece of improvement plan text.",
                      "url": "https://example.com/popt02_iplan_04.html"
                    }
                  ]
                }
              ]
         },
         {
              "id": "option_no",
              "title": "None of these",
              "helpfulResource": {
                "displayText": "Choose this if your workload does not follow these best practices.",
                "url": "https://example.com/popt02_iplan_none.html"
              }
              
            }
```

## 风险规则部分
<a name="lenses-format-risk-rules"></a>

本部分定义了所选选项如何确定风险等级。

您最多可以为每个问题定义三条风险规则，每个风险等级各一条。
+ `condition`：对应问题风险等级的选项的布尔表达式，或 `default`。

  每个问题都必须有一个 `default` 风险规则。
+ `risk`：表示与条件相关的风险。有效值包括 `HIGH_RISK`、`MEDIUM_RISK` 和 `NO_RISK`。

风险规则的顺序很重要。第一个评估为 `true` 的 `condition` 将设定问题的风险。实施风险规则的常见模式是从风险最小（通常也最精细）的规则开始，然后逐步上升到风险最大（最不具体）的规则。

例如：

```
 "riskRules": [
       {
         "condition": "choice_1 && choice_2 && choice_3",
         "risk": "NO_RISK"   
       },
       {
         "condition": "((choice_1 || choice_2) && choice_3) || (!choice_1 && choice_3)",
         "risk": "MEDIUM_RISK"
       },
       {
         "condition": "default",
         "risk": "HIGH_RISK"
       }
 ]
```

如果问题有三个选项（`choice_1`、`choice_2` 和`choice_3`），则这些风险规则会导致以下行为：
+ 如果选中所有三个选项，则没有风险。
+ 如果选中 `choice_1` 或 `choice_2`，**并且**还选中 `choice_3`，则为中等风险。
+ 如果**未**选中 `choice_1` 但选中了 `choice_3`，则也为中等风险。
+ 如果前面的这些条件都不为 true，则为高风险。