

# 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 個字元之間，且只能包含英數字元和底線 (「\_」) 字元。支柱中使用的 ID 不得重複。

  將您的問題與 Framework 的支柱相對應時，請使用下列 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 個字元，且只能包含英數字元和底線 (「\_」) 字元。問題中使用的 ID 不得重複。
+ `title`：問題的標題。標題長度上限為 128 個字元。
+ `description`：更詳細地描述問題。描述長度上限為 2048 個字元。
+ `helpfulResource displayText`：選用。此文字提供有關問題的有用資訊。文字長度上限為 2048 個字元。若已指定 `helpfulResource url`，則也必須指定此值。
+ `helpfulResource url`：選用。更詳細說明問題的 URL 資源。URL 的開頭必須為 `http://` 或 `https://`。

**注意**  
 將自訂鏡頭工作負載同步至 Jira 時，問題會顯示問題的「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 個字元之間，且只能包含英數字元和底線 (「\_」) 字元。問題的每個選項都必須有指定的唯一 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 時，選項會顯示問題和選項的「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，則表示有高風險。