

# 建立 AWS IoT Wireless 的記錄角色和政策
<a name="create-logging-role-policy"></a>

下列顯示如何建立僅適用於 AWS IoT Wireless 資源的記錄角色。如果您也想要建立 AWS IoT Core 的記錄角色，請參閱 [https://docs.aws.amazon.com/iot/latest/developerguide/create-logging-role.html](https://docs.aws.amazon.com/iot/latest/developerguide/create-logging-role.html)。

## 建立 AWS IoT Wireless 的記錄角色
<a name="logging-role"></a>

啟用記錄功能之前，您必須先建立 IAM 角色和授予代表您監控 AWS IoT Wireless 活動之 AWS 許可的政策。

**建立 IAM 角色進行記錄**  
若要建立 AWS IoT Wireless 記錄角色，請開啟 [Roles hub of the IAM console](https://console.aws.amazon.com/iam/home#/roles) (IAM 主控台的角色中樞)，然後選擇 **Create role** (建立角色)。

1. 在 **Select type of trusted entity** (選取信任的實體類型) 下，選擇 **Another AWS account** (另一個 帳戶)。

1. 在 **Account ID** (帳戶 ID) 中，輸入您的 AWS 帳戶 ID，然後選擇 **Next: Permissions** (下一步：許可)。

1. 在搜尋方塊中，輸入 **AWSIoTWirelessLogging**。

1. 選取名為 **AWSIoTWirelessLogging** 之政策旁邊的方塊，然後選擇 **Next: Tags** (下一步：標籤)。

1. 選擇 **下一步：檢閱**。

1. 在 **Role name** (角色名稱) 中，輸入 **IoTWirelessLogsRole**，然後選擇 **Create role** (建立角色)。

**編輯 IAM 角色的信任關係**  
在執行前一個步驟之後顯示的確認訊息中，選擇您已建立的角色名稱 (**IoTWirelessLogsRole**)。接下來，您將編輯角色以新增下列信任關係。

1. 在角色 **IoTWirelessLogsRole** 的 **Summary** (摘要) 區段中，選擇 **Trust relationships** (信任關係) 標籤，然後選擇 **Edit trust relationship** (編輯信任關係)。

1. 在 **Policy Document** (政策文件) 中，變更 `Principal` 屬性以看起來像此範例。

   ```
   "Principal": { 
       "Service": "iotwireless.amazonaws.com" 
   },
   ```

   在您變更 `Principal` 屬性之後，完整政策文件應該看起來像此範例。

   ```
   {
     "Version": "2012-10-17",
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
           "Service": "iotwireless.amazonaws.com"
         },
         "Action": "sts:AssumeRole",
         "Condition": {}
       }
     ]
   }
   ```

1. 若要儲存您的變更，請選擇 **Update Trust Policy** (更新信任政策)。

## AWS IoT Wireless 的記錄政策
<a name="logging-policy"></a>

下列政策文件提供了角色政策及信任政策，用以允許 AWS IoT Wireless 代表您將日誌項目提交給 CloudWatch。

**注意**  
當您建立記錄角色 (**IoTWirelessLogsRole**) 時，便會自動為您建立 AWS 受管政策文件。

**角色政策**  
下列顯示角色政策文件。

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:DescribeLogGroups",
                "logs:DescribeLogStreams",
                "logs:PutLogEvents"
            ],
            "Resource": "arn:aws:logs:*:*:log-group:/aws/iotwireless*"
        }
    ]
}
```

**僅記錄 AWS IoT Wireless 活動的信任政策**  
下列顯示僅用於記錄 AWS IoT Wireless 活動的信任政策。

```
{
     "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "",
          "Effect": "Allow",
          "Principal": {
            "Service": [
            "iotwireless.amazonaws.com"
            ]
          },
          "Action": "sts:AssumeRole"
        }
      ]
    }
```

如果您已建立 IAM 角色以同時記錄 AWS IoT Core 活動，則政策文件允許記錄這兩個活動。如需建立 AWS IoT Core 記錄角色的相關資訊，請參閱 [https://docs.aws.amazon.com/iot/latest/developerguide/create-logging-role.html](https://docs.aws.amazon.com/iot/latest/developerguide/create-logging-role.html)。

## 後續步驟
<a name="logging-role-next-steps"></a>

您已了解如何建立記錄角色來記錄 AWS IoT Wireless 資源。根據預設，記錄的日誌層級為 `ERROR`，所以如果您只想要看到錯誤資訊，請移至 [檢視 CloudWatch AWS IoT Wireless 日誌項目](cwl-format.md)，藉由檢視記錄項目來監控您的無線資源。

如果想要記錄項目中有更多資訊，您可以為您的資源或不同的事件類型設定預設日誌層級，例如將日誌層級設定為 `INFO`。如需設定資源記錄的相關資訊，請參閱 [設定 AWS IoT Wireless 資源的記錄](configure-resource-logging.md)。