

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

# 將規則組態檔案上傳至 Amazon Managed Service for Prometheus
<a name="AMP-rules-upload"></a>

知道您在規則組態檔案中想要哪些規則後，您可以在 主控台中建立和編輯規則，也可以使用 主控台或 上傳檔案 AWS CLI。

**注意**  
如果您正在執行 Amazon EKS 叢集，您也可以使用 [AWS Controllers for Kubernetes ](integrating-ack.md)上傳規則組態檔案。

**使用 Amazon Managed Service for Prometheus 主控台編輯或取代您的規則組態並建立命名空間**

1. 開啟 Amazon Managed Service for Prometheus 主控台，位於 [https://console.aws.amazon.com/prometheus/](https://console.aws.amazon.com/prometheus/home)。

1. 選擇頁面左上角的功能表圖示，然後選擇**所有工作區**。

1. 選擇工作區的工作區 ID，然後選擇**規則管理**索引標籤。

1. 選擇**新增命名空間**。

1. 選擇**選擇檔案**，然後選取規則定義檔案。

   或者，您也可以選取定義**組態**，直接在 Amazon Managed Service for Prometheus 主控台中建立和編輯規則定義檔案。這將建立您在上傳之前編輯的範例預設定義檔案。

1. (選用) 若要將標籤新增至命名空間，請選擇**新增標籤**。

   之後，在 **Key** (索引鍵) 中，輸入標籤的名稱。您可以在 **Value (值)** 中為標籤新增選用值。

   若要新增另一個標籤，請再次選擇**新增標籤**。

1. 選擇**繼續**。Amazon Managed Service for Prometheus 會建立名稱與所選規則檔案相同的新命名空間。

**使用 AWS CLI 將警示管理員組態上傳至新命名空間中的工作區**

1. Base64 會對警示管理員檔案的內容進行編碼。在 Linux 系統上，您可使用下列命令：

   ```
   base64 {{input-file}} {{output-file}}
   ```

   在 macOS 系統上，您可使用下列命令：

   ```
   openssl base64 {{input-file}} {{output-file}}
   ```

1. 輸入以下其中一個命令，建立命名空間並上傳檔案。

   在第 2 AWS CLI 版上，輸入：

   ```
   aws amp create-rule-groups-namespace --data file://{{path_to_base_64_output_file}} --name {{namespace-name}}  --workspace-id {{my-workspace-id}} --region {{region}}
   ```

   在第 1 AWS CLI 版上，輸入：

   ```
   aws amp create-rule-groups-namespace --data fileb://{{path_to_base_64_output_file}} --name {{namespace-name}}  --workspace-id {{my-workspace-id}} --region {{region}}
   ```

1. 警示管理員組態需要幾秒鐘才會變成啟用中。若要檢查狀態，請輸入以下命令：

   ```
   aws amp describe-rule-groups-namespace --workspace-id {{workspace_id}} --name {{namespace-name}} --region {{region}}
   ```

   如果 `status` 是 `ACTIVE`，則表示您的規則檔案已生效。