

• 2026 年 4 月 30 日之後， AWS Systems Manager CloudWatch Dashboard 將不再可用。客戶可以繼續使用 Amazon CloudWatch 主控台來檢視、建立和管理其 Amazon CloudWatch 儀表板，就像現在一樣。如需詳細資訊，請參閱 [Amazon CloudWatch Dashboard 文件](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

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

# 建立執行 Chef 配方的關聯
<a name="systems-manager-state-manager-chef"></a>

您可以使用 `AWS-ApplyChefRecipes` SSM 文件來建立執行 Chef 配方的 State Manager 關聯。State Manager 是 AWS Systems Manager中的工具。您可以使用 `AWS-ApplyChefRecipes` SSM 文件，將 Linux 型 Systems Manager 受管節點設定為目標。本文件提供執行 Chef 配方的下列優點：
+ 支援多個 Chef 版本 (Chef 11 到 Chef 18)。
+ 自動在目標節點上安裝 Chef 用戶端軟體。
+ 在目標節點上選用地執行 [Systems Manager 合規檢查](systems-manager-compliance.md)，並將合規檢查的結果存放在 Amazon Simple Storage Service (Amazon S3) 儲存貯體中。
+ 在單一文件執行中執行多個食譜和配方。
+ 選用地在 `why-run` 模式下執行配方，以顯示哪些配方會對目標節點進行變更，而無須實際進行變更。
+ 選用地將自訂 JSON 屬性套用到 `chef-client` 執行。
+ 選擇性地從存放在指定位置的來源檔案套用自訂 JSON 屬性。

您可以使用 [Git](#state-manager-chef-git)、[GitHub](#state-manager-chef-github)、[HTTP](#state-manager-chef-http) 或 [Amazon S3](#state-manager-chef-s3) 儲存貯體作為您在 `AWS-ApplyChefRecipes` 文件中所指定 Chef 碼元書和配方的下載來源。

**注意**  
執行 Chef 配方的關聯在 macOS 上不受支援。

## 開始使用
<a name="state-manager-chef-prereqs"></a>

在您建立 `AWS-ApplyChefRecipes` 文件前，請先準備您的 Chef 碼元書和技術指南儲存庫。如果您還沒有想要使用的Chef技術指南，則可以開始使用 AWS 為您準備的測試`HelloWorld`技術指南。`AWS-ApplyChefRecipes` 文件根據預設已指向此食譜。您的食譜應根據以下目錄結構進行相似的設定。在以下範例中，`jenkins` 和 `nginx` 是 Chef 碼元書範例，可在 Chef 網站上的 [https://supermarket.chef.io/](https://supermarket.chef.io/) 中取得。

雖然 AWS 無法正式支援 [https://supermarket.chef.io/](https://supermarket.chef.io/) 網站上的技術指南，但其中許多都使用 `AWS-ApplyChefRecipes` 文件。以下是在您測試社群技術指南時應確定的條件範例：
+ 技術指南應支援您設為目標的 Systems Manager 受管節點的 Linux 型作業系統。
+ 此碼元書針對您使用的 Chef 用戶端版本 (Chef 11 到 Chef 18) 應為有效。
+ 碼元書與 Chef Infra Client 相容，並且不需要 Chef 伺服器。

驗證您可以連接到 `Chef.io` 網站，使得您在執行清單中指定的任何碼元書都能在 Systems Manager 文件 (SSM 文件) 執行時進行安裝。支援使用巢狀 `cookbooks` 資料夾，但並非必要；您可以將食譜直接存放在根層級下。

```
<Top-level directory, or the top level of the archive file (ZIP or tgz or tar.gz)>
    └── cookbooks (optional level)
        ├── jenkins
        │   ├── metadata.rb
        │   └── recipes
        └── nginx
            ├── metadata.rb
            └── recipes
```

**重要**  
請注意，在建立執行 Chef 配方的 State Manager 關聯前，除非您將 **Chef 用戶端版本**的值設為 `None`，否則執行會在 Systems Manager 受管節點上安裝 Chef 用戶端軟體。此操作會使用 Chef 的安裝指令碼來代表您安裝 Chef 元件。在您執行 `AWS-ApplyChefRecipes` 文件前，請確認您的企業符合任何適用的法規需求，包括適用於使用 Chef 軟體的授權條款。如需詳細資訊，請參閱 [Chef 網站](https://www.chef.io/)。

Systems Manager 可以將合規報告交付至 S3 儲存貯體、Systems Manager 主控台，或提供合規結果來回應 Systems Manager API 命令。若要執行 Systems Manager 合規報告，連接至 Systems Manager 受管節點的執行個體設定檔必須具備寫入 S3 儲存貯體的許可。執行個體設定檔必須具備使用 Systems Manager `PutComplianceItem` API 的許可。如需有關 Systems Manager 合規的詳細資訊，請參閱 [AWS Systems Manager合規](systems-manager-compliance.md)。

### 將文件執行記錄於日誌
<a name="state-manager-chef-logging"></a>

當您透過使用 State Manager 關聯來執行 Systems Manager 文件 (SSM 文件) 時，您可以設定關聯來選擇執行文件的輸出，並且可以將輸出傳送到 Amazon Simple Storage Service (Amazon S3) 或 Amazon CloudWatch Logs (CloudWatch Logs)。為了協助讓關聯完成執行時的故障診斷更為容易，請驗證關聯已設為將命令輸出寫入 Amazon Simple Storage Service (Amazon S3) 儲存貯體或 CloudWatch Logs。如需詳細資訊，請參閱[在 Systems Manager 中使用關聯](state-manager-associations.md)。

## 執行配方時將 JSON 屬性套用至目標
<a name="apply-custom-json-attributes"></a>

您可以為 Chef 用戶端指定 JSON 屬性，以便在關聯執行期間將其套用至目標節點。設定關聯時，您可以提供原始 JSON 或提供存放在 Amazon S3 中之 JSON 檔案的路徑。

當您想要自訂配方的執行方式而不修改配方本身時，您可以使用 JSON 屬性，例如：
+ **覆寫少量的屬性**

  使用自訂 JSON 以避免為適應細微差異而必須維護多個版本的配方。
+ **提供變數值**

  使用自訂 JSON 指定可能會在不同次執行中變更的值。例如，如果您的 Chef 碼元書設定接受付款的第三方應用程式，您可以使用自訂 JSON 來指定付款端點 URL。

**在原始 JSON 中指定屬性**

以下是您可以用來為 Chef 配方指定自訂 JSON 屬性的格式範例。

```
{"filepath":"/tmp/example.txt", "content":"Hello, World!"}
```

**指定 JSON 檔案的路徑**  
以下是您可以用來為 Chef 配方指定自訂 JSON 屬性之路徑的格式範例。

```
{"sourceType":"s3", "sourceInfo":"someS3URL1"}, {"sourceType":"s3", "sourceInfo":"someS3URL2"}
```

## 使用 Git 做為食譜來源
<a name="state-manager-chef-git"></a>

`AWS-ApplyChefRecipes` 文件會使用 [aws:downloadContent](documents-command-ssm-plugin-reference.md#aws-downloadContent) 外掛程式來下載 Chef 碼元書。若要從 Git 中下載內容，請如以下範例所示指定 JSON 格式的 Git 儲存庫相關資訊。將每個 *example-resource-placeholder* 替換為您自己的資訊。

```
{
   "repository":"GitCookbookRepository",
   "privateSSHKey":"{{ssm-secure:ssh-key-secure-string-parameter}}",
   "skipHostKeyChecking":"false",
   "getOptions":"branch:refs/head/main",
   "username":"{{ssm-secure:username-secure-string-parameter}}",
   "password":"{{ssm-secure:password-secure-string-parameter}}"
}
```

## 使用 GitHub 做為逐步指南來源
<a name="state-manager-chef-github"></a>

`AWS-ApplyChefRecipes` 文件會使用 [aws:downloadContent](documents-command-ssm-plugin-reference.md#aws-downloadContent) 外掛程式來下載碼元書。若要從 GitHub 下載內容，請如以下範例所示指定 JSON 格式的 GitHub 儲存庫相關資訊。將每個 *example-resource-placeholder* 替換為您自己的資訊。

```
{
   "owner":"TestUser",
   "repository":"GitHubCookbookRepository",
   "path":"cookbooks/HelloWorld",
   "getOptions":"branch:refs/head/main",
   "tokenInfo":"{{ssm-secure:token-secure-string-parameter}}"
}
```

## 使用 HTTP 做為食譜來源
<a name="state-manager-chef-http"></a>

您可以將 Chef 碼元書以單一 `.zip` 或 `tar.gz` 檔案或目錄結構的形式，儲存在一個自訂 HTTP 位置。若要從 HTTP 下載內容，請如以下範例所示以 JSON 格式指定相關檔案或目錄的路徑。將每個 *example-resource-placeholder* 替換為您自己的資訊。

```
{
   "url":"https://my.website.com/chef-cookbooks/HelloWorld.zip",
   "allowInsecureDownload":"false",
   "authMethod":"Basic",
   "username":"{{ssm-secure:username-secure-string-parameter}}",
   "password":"{{ssm-secure:password-secure-string-parameter}}"
}
```

## 使用 Amazon Simple Storage Service (Amazon S3) 作為技術指南來源
<a name="state-manager-chef-s3"></a>

您也能以單一 `.zip` 或 `tar.gz` 檔案或目錄結構的形式，在 Amazon S3 中儲存和下載 Chef 碼元書。若要從 Amazon S3 下載內容，請如以下範例所示以 JSON 格式指定相關檔案的路徑。將每個 *example-resource-placeholder* 替換為您自己的資訊。

**範例 1：下載特定食譜**

```
{
   "path":"https://s3.amazonaws.com/chef-cookbooks/HelloWorld.zip"
}
```

**範例 2：下載目錄的內容**

```
{
   "path":"https://s3.amazonaws.com/chef-cookbooks-test/HelloWorld"
}
```

**重要**  
如果您指定 Amazon S3，則必須使用 `AmazonS3ReadOnlyAccess`政策來設定受管節點上的 AWS Identity and Access Management (IAM) 執行個體描述檔。如需詳細資訊，請參閱[設定 Systems Manager 所需的執行個體許可](setup-instance-permissions.md)。

## 建立執行 Chef 配方的關聯 (主控台)
<a name="state-manager-chef-console"></a>

以下程序說明如何使用 Systems Manager 主控台來建立使用 `AWS-ApplyChefRecipes` 文件執行 Chef 碼元書的 State Manager 關聯。

1. 在 https：//[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 開啟 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇 **State Manager**。

1. 選擇 **State Manager**，然後選擇 **Create association** (建立關聯)。

1. 針對 **Name (名稱)**，輸入可協助您記住關聯用途的名稱。

1. 在 **Document** (文件) 清單中，請選擇 **`AWS-ApplyChefRecipes`**。

1. 在**參數**中，為**來源類型**選取 **Git**、**GitHub**、**HTTP** 或 **S3**。

1. 對於**來源資訊**，請使用您在步驟 6 中選取的**來源類型**對應的適當格式，輸入食譜來源資訊。如需詳細資訊，請參閱下列主題：
   + [使用 Git 做為食譜來源](#state-manager-chef-git)
   + [使用 GitHub 做為逐步指南來源](#state-manager-chef-github)
   + [使用 HTTP 做為食譜來源](#state-manager-chef-http)
   + [使用 Amazon Simple Storage Service (Amazon S3) 作為技術指南來源](#state-manager-chef-s3)

1. 在 **Run list (執行清單)** 中，以以下格式列出您希望執行的配方，並以逗號分隔每個配方，如下所示。請不要在逗號後方包含空格。將每個 *example-resource-placeholder* 替換為您自己的資訊。

   ```
   recipe[cookbook-name1::recipe-name],recipe[cookbook-name2::recipe-name]
   ```

1. (選用) 指定您希望 Chef 用戶端傳遞至目標節點的自訂 JSON 屬性。

   1. 在 **JSON 屬性內容**中，新增任何您希望 Chef 用戶端傳遞至目標節點的屬性。

   1. 在 **JSON 屬性來源**中，新增任何您希望 Chef 用戶端傳遞至目標節點之屬性的路徑。

   如需詳細資訊，請參閱[執行配方時將 JSON 屬性套用至目標](#apply-custom-json-attributes)。

1. 針對 **Chef 用戶端版本**，指定 Chef 版本。有效值為 `11` 到 `18` 中的一個或 `None`。若指定 `11` 至 `18` 的一個數字 (含首尾兩個值)，Systems Manager 會在目標節點上安裝正確的 Chef 用戶端版本。如果指定 `None`，在目標節點上安裝 Chef 用戶端前，Systems Manager 不會在執行文件的配方。

1. (選用) 對於 **Chef 用戶端引數**，指定您正在使用 Chef 版本支援的額外引數。如要進一步了解支援的引數，請在執行 Chef 用戶端的節點上執行 `chef-client -h`。

1. (選用) 開啟 **Why-run** 來顯示若執行配方將對目標節點進行的變更，而無須實際變更目標節點。

1. 對於 **Compliance severity** (合規嚴重性)，選擇您希望報告的 Systems Manager 合規結果嚴重性。合規報告會指出關聯狀態合規與否，以及您指定的嚴重性層級。合規報告會存放在您指定為 **Compliance report bucket** (合規報告儲存貯體) 參數 (步驟 14) 的 S3 儲存貯體中。如需合規的詳細資訊，請參閱本指南中的 [了解有關合規性的詳細資訊](compliance-about.md)。

   合規會掃描您 Chef 配方中所指定組態與節點資源組態間的量值漂移。有效值為 `Critical`、`High`、`Medium`、`Low`、`Informational`、`Unspecified` 或 `None`。如要跳過合規報告，請選擇 `None`。

1. 針對 **Compliance type (合規類型)**，請指定您希望結果報告的合規類型。有效值為 `Association` (對於 State Manager 關聯)，或是 `Custom:`*custom\$1type*。預設值為 `Custom:Chef`。

1. 對於**合規報告儲存貯體**，輸入儲存此文件執行的每個 Chef 執行相關資訊的 S3 儲存貯體，包括資源組態與合規結果。

1. 在 **Rate control** (速率控制) 區段中，設定在受管節點機群之間執行State Manager關聯的選項。如需使用速率控制的詳細資訊，請參閱 [了解 State Manager 關聯中的目標和速率控制](systems-manager-state-manager-targets-and-rate-controls.md)。

   在 **Concurrency (並行)** 中，選擇一個選項：
   + 選擇 **targets (目標)**，輸入可以同時執行關聯的目標絕對數量。
   + 選擇 **percentage (百分比)**，輸入可以同時執行關聯的目標集百分比。

   在 **Error Threshold (錯誤閾值)** 中，選擇一個選項：
   + 選擇 **errors (錯誤)**，輸入 State Manager 停止在額外目標執行關聯之前允許的錯誤絕對數量。
   + 選擇 **percentage (百分比)**，輸入 State Manager 停止在額外目標執行關聯之前允許的錯誤百分比。

1. (選用) 針對**輸出選項**，若要將命令輸出儲存至檔案，請選取**啟用將輸出寫入 S3** 方塊。在方塊中輸入儲存貯體和字首 (資料夾) 名稱。
**注意**  
授予能力以將資料寫入至 S3 儲存貯體的 S3 許可，會是指派給受管節點之執行個體設定檔的許可，而不是執行此任務之 IAM 使用者的許可。如需詳細資訊，請參閱[設定 Systems Manager 所需的執行個體許可](setup-instance-permissions.md)或[建立混合環境的 IAM 服務角色](hybrid-multicloud-service-role.md)。此外，若指定的 S3 儲存貯體位於不同的 AWS 帳戶內，請驗證與受管節點相關聯的執行個體設定檔或 IAM 服務角色是否具有寫入該儲存貯體的必要許可。

1. 選擇 **Create Association (建立關聯)**。

## 建立執行 Chef 配方的關聯 (CLI)
<a name="state-manager-chef-cli"></a>

下列程序說明如何使用 AWS Command Line Interface (AWS CLI) 建立使用 `AWS-ApplyChefRecipes` 文件執行 Chef 技術指南的State Manager關聯。

1. 如果您尚未安裝和設定 AWS Command Line Interface (AWS CLI)。

   如需相關資訊，請參閱[安裝或更新最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 執行以下其中一個命令，建立在具有指定標籤的目標節點上執行 Chef 碼元書的關聯。使用適用於您的食譜來源類型和作業系統的命令。將每個 *example-resource-placeholder* 替換為您自己的資訊。

   1. **Git 來源**

------
#### [ Linux & macOS ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" \
          --targets Key=tag:TagKey,Values=TagValue \
          --parameters '{"SourceType":["Git"],"SourceInfo":["{\"repository\":\"repository-name\", \"getOptions\": \"branch:branch-name\", \"username\": \"{{ ssm-secure:username-secure-string-parameter }}\", \"password\": \"{{ ssm-secure:password-secure-string-parameter }}\"}"], "RunList":["{\"recipe[cookbook-name-1::recipe-name]\", \"recipe[cookbook-name-2::recipe-name]\"}"], "JsonAttributesContent": ["{custom-json-content}"], "JsonAttributesSources": "{\"sourceType\":\"s3\", \"sourceInfo\":\"s3-bucket-endpoint-1\"}, {\"sourceType\":\"s3\", \"sourceInfo\":\"s3-bucket-endpoint-2\"}", "ChefClientVersion": ["version-number"], "ChefClientArguments":["{chef-client-arguments}"], "WhyRun": boolean, "ComplianceSeverity": ["severity-value"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["s3-bucket-name"]}' \
          --association-name "name" \
          --schedule-expression "cron-or-rate-expression"
      ```

------
#### [ Windows ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" ^
          --targets Key=tag:TagKey,Values=TagValue ^
          --parameters '{"SourceType":["Git"],"SourceInfo":["{\"repository\":\"repository-name\", \"getOptions\": \"branch:branch-name\", \"username\": \"{{ ssm-secure:username-secure-string-parameter }}\", \"password\": \"{{ ssm-secure:password-secure-string-parameter }}\"}"], "RunList":["{\"recipe[cookbook-name-1::recipe-name]\", \"recipe[cookbook-name-2::recipe-name]\"}"], "JsonAttributesContent": ["{custom-json}"], "JsonAttributesSources": "{\"sourceType\":\"s3\", \"sourceInfo\":\"s3-bucket-endpoint-1\"}, {\"sourceType\":\"s3\", \"sourceInfo\":\"s3-bucket-endpoint-2\"}", "ChefClientVersion": ["version-number"], "ChefClientArguments":["{chef-client-arguments}"], "WhyRun": boolean, "ComplianceSeverity": ["severity-value"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["s3-bucket-name"]}' ^
          --association-name "name" ^
          --schedule-expression "cron-or-rate-expression"
      ```

------

   1. **GitHub 來源**

------
#### [ Linux & macOS ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" \
          --targets Key=tag:TagKey,Values=TagValue \
          --parameters '{"SourceType":["GitHub"],"SourceInfo":["{\"owner\":\"owner-name\", \"repository\": \"name\", \"path\": \"path-to-directory-or-cookbook-to-download\", \"getOptions\": \"branch:branch-name\"}"], "RunList":["{\"recipe[cookbook-name-1::recipe-name]\", \"recipe[cookbook-name-2::recipe-name]\"}"], "JsonAttributesContent": ["{custom-json}"], "ChefClientVersion": ["version-number"], "ChefClientArguments":["{chef-client-arguments}"], "WhyRun": boolean, "ComplianceSeverity": ["severity-value"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["s3-bucket-name"]}' \
          --association-name "name" \
          --schedule-expression "cron-or-rate-expression"
      ```

------
#### [ Windows ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" ^
          --targets Key=tag:TagKey,Values=TagValue \
          --parameters '{"SourceType":["GitHub"],"SourceInfo":["{\"owner\":\"owner-name\", \"repository\": \"name\", \"path\": \"path-to-directory-or-cookbook-to-download\", \"getOptions\": \"branch:branch-name\"}"], "RunList":["{\"recipe[cookbook-name-1::recipe-name]\", \"recipe[cookbook-name-2::recipe-name]\"}"], "JsonAttributesContent": ["{custom-json}"], "ChefClientVersion": ["version-number"], "ChefClientArguments":["{chef-client-arguments}"], "WhyRun": boolean, "ComplianceSeverity": ["severity-value"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["s3-bucket-name"]}' ^
          --association-name "name" ^
          --schedule-expression "cron-or-rate-expression"
      ```

------

      請見此處範例。

------
#### [ Linux & macOS ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" \
          --targets Key=tag:OS,Values=Linux \
          --parameters '{"SourceType":["GitHub"],"SourceInfo":["{\"owner\":\"ChefRecipeTest\", \"repository\": \"ChefCookbooks\", \"path\": \"cookbooks/HelloWorld\", \"getOptions\": \"branch:master\"}"], "RunList":["{\"recipe[HelloWorld::HelloWorldRecipe]\", \"recipe[HelloWorld::InstallApp]\"}"], "JsonAttributesContent": ["{\"state\": \"visible\",\"colors\": {\"foreground\": \"light-blue\",\"background\": \"dark-gray\"}}"], "ChefClientVersion": ["14"], "ChefClientArguments":["{--fips}"], "WhyRun": false, "ComplianceSeverity": ["Medium"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["ChefComplianceResultsBucket"]}' \
          --association-name "MyChefAssociation" \
          --schedule-expression "cron(0 2 ? * SUN *)"
      ```

------
#### [ Windows ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" ^
          --targets Key=tag:OS,Values=Linux ^
          --parameters '{"SourceType":["GitHub"],"SourceInfo":["{\"owner\":\"ChefRecipeTest\", \"repository\": \"ChefCookbooks\", \"path\": \"cookbooks/HelloWorld\", \"getOptions\": \"branch:master\"}"], "RunList":["{\"recipe[HelloWorld::HelloWorldRecipe]\", \"recipe[HelloWorld::InstallApp]\"}"], "JsonAttributesContent": ["{\"state\": \"visible\",\"colors\": {\"foreground\": \"light-blue\",\"background\": \"dark-gray\"}}"], "ChefClientVersion": ["14"], "ChefClientArguments":["{--fips}"], "WhyRun": false, "ComplianceSeverity": ["Medium"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["ChefComplianceResultsBucket"]}' ^
          --association-name "MyChefAssociation" ^
          --schedule-expression "cron(0 2 ? * SUN *)"
      ```

------

   1. **HTTP 來源**

------
#### [ Linux & macOS ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" \
          --targets Key=tag:TagKey,Values=TagValue \
          --parameters '{"SourceType":["HTTP"],"SourceInfo":["{\"url\":\"url-to-zip-file|directory|cookbook\", \"authMethod\": \"auth-method\", \"username\": \"{{ ssm-secure:username-secure-string-parameter }}\", \"password\": \"{{ ssm-secure:password-secure-string-parameter }}\"}"], "RunList":["{\"recipe[cookbook-name-1::recipe-name]\", \"recipe[cookbook-name-2::recipe-name]\"}"], "JsonAttributesContent": ["{custom-json-content}"], "JsonAttributesSources": "{\"sourceType\":\"s3\", \"sourceInfo\":\"s3-bucket-endpoint-1\"}, {\"sourceType\":\"s3\", \"sourceInfo\":\"s3-bucket-endpoint-2\"}", "ChefClientVersion": ["version-number"], "ChefClientArguments":["{chef-client-arguments}"], "WhyRun": boolean, "ComplianceSeverity": ["severity-value"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["s3-bucket-name"]}' \
          --association-name "name" \
          --schedule-expression "cron-or-rate-expression"
      ```

------
#### [ Windows ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" ^
          --targets Key=tag:TagKey,Values=TagValue ^
          --parameters '{"SourceType":["HTTP"],"SourceInfo":["{\"url\":\"url-to-zip-file|directory|cookbook\", \"authMethod\": \"auth-method\", \"username\": \"{{ ssm-secure:username-secure-string-parameter }}\", \"password\": \"{{ ssm-secure:password-secure-string-parameter }}\"}"], "RunList":["{\"recipe[cookbook-name-1::recipe-name]\", \"recipe[cookbook-name-2::recipe-name]\"}"], "JsonAttributesContent": ["{custom-json-content}"], "JsonAttributesSources": "{\"sourceType\":\"s3\", \"sourceInfo\":\"s3-bucket-endpoint-1\"}, {\"sourceType\":\"s3\", \"sourceInfo\":\"s3-bucket-endpoint-2\"}", "ChefClientVersion": ["version-number"], "ChefClientArguments":["{chef-client-arguments}"], "WhyRun": boolean, "ComplianceSeverity": ["severity-value"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["s3-bucket-name"]}' \
          --association-name "name" ^
          --schedule-expression "cron-or-rate-expression"
      ```

------

   1. **Amazon S3 來源**

------
#### [ Linux & macOS ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" \
          --targets Key=tag:TagKey,Values=TagValue \
          --parameters '{"SourceType":["S3"],"SourceInfo":["{\"path\":\"https://s3.amazonaws.com/path_to_Zip_file,_directory,_or_cookbook_to_download\"}"], "RunList":["{\"recipe[cookbook_name1::recipe_name]\", \"recipe[cookbook_name2::recipe_name]\"}"], "JsonAttributesContent": ["{Custom_JSON}"], "ChefClientVersion": ["version_number"], "ChefClientArguments":["{chef_client_arguments}"], "WhyRun": true_or_false, "ComplianceSeverity": ["severity_value"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["amzn-s3-demo-bucket"]}' \
          --association-name "name" \
          --schedule-expression "cron_or_rate_expression"
      ```

------
#### [ Windows ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" ^
          --targets Key=tag:TagKey,Values=TagValue ^
          --parameters '{"SourceType":["S3"],"SourceInfo":["{\"path\":\"https://s3.amazonaws.com/path_to_Zip_file,_directory,_or_cookbook_to_download\"}"], "RunList":["{\"recipe[cookbook_name1::recipe_name]\", \"recipe[cookbook_name2::recipe_name]\"}"], "JsonAttributesContent": ["{Custom_JSON}"], "ChefClientVersion": ["version_number"], "ChefClientArguments":["{chef_client_arguments}"], "WhyRun": true_or_false, "ComplianceSeverity": ["severity_value"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["amzn-s3-demo-bucket"]}' ^
          --association-name "name" ^
          --schedule-expression "cron_or_rate_expression"
      ```

------

      請見此處範例。

------
#### [ Linux & macOS ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" \
          --targets "Key=tag:OS,Values= Linux" \
          --parameters '{"SourceType":["S3"],"SourceInfo":["{\"path\":\"https://s3.amazonaws.com/amzn-s3-demo-bucket/HelloWorld\"}"], "RunList":["{\"recipe[HelloWorld::HelloWorldRecipe]\", \"recipe[HelloWorld::InstallApp]\"}"], "JsonAttributesContent": ["{\"state\": \"visible\",\"colors\": {\"foreground\": \"light-blue\",\"background\": \"dark-gray\"}}"], "ChefClientVersion": ["14"], "ChefClientArguments":["{--fips}"], "WhyRun": false, "ComplianceSeverity": ["Medium"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["ChefComplianceResultsBucket"]}' \
          --association-name "name" \
          --schedule-expression "cron(0 2 ? * SUN *)"
      ```

------
#### [ Windows ]

      ```
      aws ssm create-association --name "AWS-ApplyChefRecipes" ^
          --targets "Key=tag:OS,Values= Linux" ^
          --parameters '{"SourceType":["S3"],"SourceInfo":["{\"path\":\"https://s3.amazonaws.com/amzn-s3-demo-bucket/HelloWorld\"}"], "RunList":["{\"recipe[HelloWorld::HelloWorldRecipe]\", \"recipe[HelloWorld::InstallApp]\"}"], "JsonAttributesContent": ["{\"state\": \"visible\",\"colors\": {\"foreground\": \"light-blue\",\"background\": \"dark-gray\"}}"], "ChefClientVersion": ["14"], "ChefClientArguments":["{--fips}"], "WhyRun": false, "ComplianceSeverity": ["Medium"], "ComplianceType": ["Custom:Chef"], "ComplianceReportBucket": ["ChefComplianceResultsBucket"]}' ^
          --association-name "name" ^
          --schedule-expression "cron(0 2 ? * SUN *)"
      ```

------

      系統會建立關聯，除非您指定的 cron 或 rate 表達式阻止關聯，否則系統會在目標節點上執行關聯。
**注意**  
State Manager 關聯不支援所有 Cron 和 Rate 表達式。如需針對關聯建立 Cron 和 Rate 運算式的詳細資訊，請參閱[參考：Systems Manager 的 Cron 和 Rate 運算式](reference-cron-and-rate-expressions.md)。

1. 執行以下命令來檢視您剛剛建立的關聯的狀態。

   ```
   aws ssm describe-association --association-id "ID"
   ```

## 檢視 Chef 資源合規詳細資訊
<a name="state-manager-chef-compliance"></a>

Systems Manager 在您執行 `AWS-ApplyChefRecipes` 文件時指定的 Amazon S3 **合規報告儲存貯體**值中擷取有關 Chef 受管資源的合規資訊。在 S3 儲存貯體中搜尋 Chef 資源故障相關資訊可能非常耗時。您可以改為在 Systems Manager **Compliance** (合規) 頁面中檢視此資訊。

Systems Manager 合規掃描會收集您受管節點上於最近一次 Chef 執行中建立或檢查的資源相關資訊。這些資源可包含檔案、目錄、`systemd` 服務、`yum` 套件、範本化檔案、`gem` 套件，以及相依食譜等。

**合規資源摘要**區段顯示失敗的資源計數。在以下範例中，**ComplianceType** 是 **Custom:Chef** 和不合規的一個資源。

**注意**  
`Custom:Chef` 是 `AWS-ApplyChefRecipes` 文件中的預設 **ComplianceType** 值。這個值是可自訂的。

![\[檢視 Compliance (合規) 頁面的 Compliance resources summary (合規資源摘要) 區域中的計數。\]](http://docs.aws.amazon.com/zh_tw/systems-manager/latest/userguide/images/state-manager-chef-compliance-summary.png)


**資源的詳細資訊概觀**區段會顯示不合規之 AWS 資源的相關資訊。此區段也會包含執行合規的目標 Chef 資源類型、問題嚴重性、合規狀態，以及詳細資訊的連結 (若適用的話)。

![\[檢視 Chef 受管資源故障的合規詳細資訊\]](http://docs.aws.amazon.com/zh_tw/systems-manager/latest/userguide/images/state-manager-chef-compliance-details.png)


**View output** (檢視輸出) 會顯示詳細狀態的最後 4,000 個字元。Systems Manager 會使用例外狀況做為第一個元素開始，尋找詳細訊息，並在到達 4,000 個字元配額之前顯示它們。這個程序會顯示拋出例外狀況之前的輸出日誌訊息，也就是與故障診斷最相關的訊息。

如需如何檢視合規資訊的相關資訊，請參閱 [AWS Systems Manager合規](systems-manager-compliance.md)。

**重要**  
若State Manager關聯失敗，則不會報告任何合規資料。例如，若 Systems Manager 嘗試從節點沒有存取許可的 S3 儲存貯體下載 Chef 碼元書，則關聯會失敗，Systems Manager 也不會報告任何合規資料。