

支援終止通知：2026 年 5 月 20 日， AWS 將終止對 的支援 AWS IoT Events。2026 年 5 月 20 日之後，您將無法再存取 AWS IoT Events 主控台或 AWS IoT Events 資源。如需詳細資訊，請參閱[AWS IoT Events 終止支援](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-end-of-support.html)。

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

# 設定 AWS IoT Events
<a name="iotevents-start"></a>

本節提供設定 的指南 AWS IoT Events，包括建立 AWS 帳戶、設定必要的許可，以及建立管理 資源存取的角色。

**Topics**
+ [設定 AWS 帳戶](#set-up-aws-account)
+ [設定 的許可 AWS IoT Events](iotevents-permissions.md)

## 設定 AWS 帳戶
<a name="set-up-aws-account"></a>

### 註冊 AWS 帳戶
<a name="sign-up-for-aws"></a>

如果您沒有 AWS 帳戶，請完成下列步驟來建立一個。

**註冊 AWS 帳戶**

1. 開啟 [https://portal.aws.amazon.com/billing/signup](https://portal.aws.amazon.com/billing/signup)。

1. 請遵循線上指示進行。

   部分註冊程序需接收來電或簡訊，並在電話鍵盤輸入驗證碼。

   當您註冊 時 AWS 帳戶，*AWS 帳戶根使用者*會建立 。根使用者有權存取該帳戶中的所有 AWS 服務 和資源。作為安全最佳實務，請將管理存取權指派給使用者，並且僅使用根使用者來執行[需要根使用者存取權的任務](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_root-user.html#root-user-tasks)。

AWS 會在註冊程序完成後傳送確認電子郵件給您。您可以隨時登錄 [https://aws.amazon.com/](https://aws.amazon.com/) 並選擇**我的帳戶**，以檢視您目前的帳戶活動並管理帳戶。

### 建立具有管理存取權的使用者
<a name="create-an-admin"></a>

註冊 後 AWS 帳戶，請保護 AWS 帳戶根使用者、啟用 AWS IAM Identity Center和建立管理使用者，以免將根使用者用於日常任務。

**保護您的 AWS 帳戶根使用者**

1.  選擇**根使用者**並輸入 AWS 帳戶 您的電子郵件地址，以帳戶擁有者[AWS 管理主控台](https://console.aws.amazon.com/)身分登入 。在下一頁中，輸入您的密碼。

   如需使用根使用者登入的說明，請參閱 *AWS 登入 使用者指南*中的[以根使用者身分登入](https://docs.aws.amazon.com/signin/latest/userguide/console-sign-in-tutorials.html#introduction-to-root-user-sign-in-tutorial)。

1. 若要在您的根使用者帳戶上啟用多重要素驗證 (MFA)。

   如需說明，請參閱《*IAM 使用者指南*》中的[為您的 AWS 帳戶 根使用者 （主控台） 啟用虛擬 MFA 裝置](https://docs.aws.amazon.com/IAM/latest/UserGuide/enable-virt-mfa-for-root.html)。

**建立具有管理存取權的使用者**

1. 啟用 IAM Identity Center。

   如需指示，請參閱《AWS IAM Identity Center 使用者指南》**中的[啟用 AWS IAM Identity Center](https://docs.aws.amazon.com//singlesignon/latest/userguide/get-set-up-for-idc.html)。

1. 在 IAM Identity Center 中，將管理存取權授予使用者。

   如需使用 IAM Identity Center 目錄 做為身分來源的教學課程，請參閱*AWS IAM Identity Center 《 使用者指南*》中的[使用預設值設定使用者存取 IAM Identity Center 目錄](https://docs.aws.amazon.com//singlesignon/latest/userguide/quick-start-default-idc.html)。

**以具有管理存取權的使用者身分登入**
+ 若要使用您的 IAM Identity Center 使用者簽署，請使用建立 IAM Identity Center 使用者時傳送至您電子郵件地址的簽署 URL。

  如需使用 IAM Identity Center 使用者登入的說明，請參閱*AWS 登入 《 使用者指南*》中的[登入 AWS 存取入口網站](https://docs.aws.amazon.com/signin/latest/userguide/iam-id-center-sign-in-tutorial.html)。

**指派存取權給其他使用者**

1. 在 IAM Identity Center 中，建立一個許可集來遵循套用最低權限的最佳實務。

   如需指示，請參閱《AWS IAM Identity Center 使用者指南》**中的[建立許可集](https://docs.aws.amazon.com//singlesignon/latest/userguide/get-started-create-a-permission-set.html)。

1. 將使用者指派至群組，然後對該群組指派單一登入存取權。

   如需指示，請參閱《AWS IAM Identity Center 使用者指南》**中的[新增群組](https://docs.aws.amazon.com//singlesignon/latest/userguide/addgroups.html)。

# 設定 的許可 AWS IoT Events
<a name="iotevents-permissions"></a>

實作適當的許可對於安全且有效地使用 至關重要 AWS IoT Events。本節說明使用 的某些功能所需的許可 AWS IoT Events。您可以使用 AWS CLI 命令或 AWS Identity and Access Management (IAM) 主控台來建立角色和相關聯的許可政策，以存取 資源或執行特定 函數 AWS IoT Events。

[IAM 使用者指南](https://docs.aws.amazon.com/IAM/latest/UserGuide/)提供有關安全控制 AWS 資源存取許可的詳細資訊。如需 的特定資訊 AWS IoT Events，請參閱 [的動作、資源和條件索引鍵 AWS IoT Events](https://docs.aws.amazon.com/IAM/latest/UserGuide/list_awsiotevents.html)。

若要使用 IAM 主控台建立和管理角色和許可，請參閱 [IAM 教學課程：使用 IAM 角色在 AWS 帳戶之間委派存取權](https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html)。

**注意**  
金鑰可以是 1-128 個字元，可包含：  
大小寫字母 a-z
數字 0-9
特殊字元 **-**、**\$1** 或 **：**。

# 的動作許可 AWS IoT Events
<a name="iotevents-permissions-event-actions"></a>

AWS IoT Events 可讓您觸發使用其他 AWS 服務的動作。若要這樣做，您必須授予代表您執行這些動作的 AWS IoT Events 許可。本節包含動作清單和範例政策，該政策會授予在您的 資源上執行所有這些動作的許可。視需要變更*區域*和*帳戶 ID *參考。如果可能，您也應該變更萬用字元 (\$1)，以參考將存取的特定資源。您可以使用 IAM 主控台授予 許可， AWS IoT Events 以傳送您定義的 Amazon SNS 提醒。

<a name="build-in-actions-intro"></a>AWS IoT Events 支援下列動作，可讓您使用計時器或設定變數：<a name="build-in-actions"></a>
+ [`setTimer`](built-in-actions.md#iotevents-set-timer) 來建立計時器。
+ [`resetTimer`](built-in-actions.md#iotevents-reset-timer) 以重設計時器。
+ [`clearTimer`](built-in-actions.md#iotevents-clear-timer) 刪除計時器。
+ [`setVariable`](built-in-actions.md#iotevents-set-variable) 來建立變數。

<a name="work-with-aws-services-intro"></a>AWS IoT Events 支援下列動作，可讓您使用 AWS 服務：<a name="work-with-aws-services"></a>
+ [`iotTopicPublish`](iotevents-other-aws-services.md#iotevents-iotcore) 在 MQTT 主題上發佈訊息。
+ [`iotEvents`](iotevents-other-aws-services.md#iotevents-iteinput) 將資料傳送至 AWS IoT Events 做為輸入值。
+ [`iotSiteWise`](iotevents-other-aws-services.md#iotevents-iotsitewise) 將資料傳送至 AWS IoT SiteWise中的資產屬性。
+ [`dynamoDB`](iotevents-other-aws-services.md#iotevents-dynamodb) 將資料傳送至 Amazon DynamoDB 資料表。
+ [`dynamoDBv2`](iotevents-other-aws-services.md#iotevents-dynamodbv2) 將資料傳送至 Amazon DynamoDB 資料表。
+ [`firehose`](iotevents-other-aws-services.md#iotevents-firehose) 將資料傳送至 Amazon Data Firehose 串流。
+ [`lambda`](iotevents-other-aws-services.md#iotevents-lambda) 叫用 AWS Lambda 函數。
+ [`sns`](iotevents-other-aws-services.md#iotevents-sns) 以推送通知的形式傳送資料。
+ [`sqs`](iotevents-other-aws-services.md#iotevents-sqs) 將資料傳送至 Amazon SQS 佇列。

**Example 政策**    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iot:Publish",
            "Resource": "arn:aws:iot:us-east-1:123456789012:topic/*"
        },
        {
            "Effect": "Allow",
            "Action": "iotevents:BatchPutMessage",
            "Resource": "arn:aws:iotevents:us-east-1:123456789012:input/*"
        },
        {
            "Effect": "Allow",
            "Action": "iotsitewise:BatchPutAssetPropertyValue",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "dynamodb:PutItem",
            "Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "firehose:PutRecord",
                "firehose:PutRecordBatch"
            ],
            "Resource": "arn:aws:firehose:us-east-1:123456789012:deliverystream/*"
        },
        {
            "Effect": "Allow",
            "Action": "lambda:InvokeFunction",
            "Resource": "arn:aws:lambda:us-east-1:123456789012:function:*"
        },
        {
            "Effect": "Allow",
            "Action": "sns:Publish",
            "Resource": "arn:aws:sns:us-east-1:123456789012:*"
        },
        {
            "Effect": "Allow",
            "Action": "sqs:SendMessage",
            "Resource": "arn:aws:sqs:us-east-1:123456789012:*"
        }
    ]
}
```

# 保護 中的輸入資料 AWS IoT Events
<a name="iotevents-permissions-input-data"></a>

請務必考慮誰可以授予輸入資料的存取權，以便在偵測器模型中使用。如果您有想要限制整體許可的使用者或實體，但允許建立或更新偵測器模型，您還必須授予該使用者或實體更新輸入路由的許可。這表示除了授予 `iotevents:CreateDetectorModel`和 的許可`iotevents:UpdateDetectorModel`，您還必須授予 的許可`iotevents:UpdateInputRouting`。

**Example**  
下列政策會新增 的許可`iotevents:UpdateInputRouting`。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "updateRoutingPolicy",
            "Effect": "Allow",
            "Action": [
                "iotevents:UpdateInputRouting"
            ],
            "Resource": "*"
        }
    ]
}
```

您可以為 "`*`" 指定輸入 Amazon Resource Name (ARNs) 的清單，而不是萬用字元 "`Resource`"，以將此許可限制為特定輸入。這可讓您限制存取由使用者或實體建立或更新的偵測器模型所耗用的輸入資料。

# 的 Amazon CloudWatch 記錄角色政策 AWS IoT Events
<a name="iotevents-permissions-cloudwatch"></a>

下列政策文件提供角色政策和信任政策，允許 AWS IoT Events 代表您將日誌提交至 CloudWatch。

角色政策：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:PutMetricFilter",
                "logs:PutRetentionPolicy",
                "logs:GetLogEvents",
                "logs:DeleteLogStream"
            ],
            "Resource": [
                "arn:aws:logs:*:*:*"
            ]
        }
    ]
}
```

------

信任政策：

------
#### [ JSON ]

****  

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

------

您也需要連接到使用者的 IAM 許可政策，以允許使用者傳遞角色，如下所示。如需詳細資訊，請參閱《*IAM 使用者指南*》中的[授予使用者將角色傳遞至 AWS 服務的許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html)。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "iam:GetRole",
                "iam:PassRole"
            ],
            "Resource": "arn:aws:iam::123456789012:role/Role_To_Pass"
        }
    ]
}
```

------

您可以使用下列命令來放置 CloudWatch 日誌的資源政策。這可讓 AWS IoT Events 將日誌事件放入 CloudWatch 串流。

```
aws logs put-resource-policy --policy-name ioteventsLoggingPolicy --policy-document "{ \"Version\": \"2012-10-17\",		 	 	  \"Statement\": [ { \"Sid\": \"IoTEventsToCloudWatchLogs\", \"Effect\": \"Allow\", \"Principal\": { \"Service\": [ \"iotevents.amazonaws.com\" ] }, \"Action\":\"logs:PutLogEvents\", \"Resource\": \"*\" } ] }" 
```

使用下列命令來放置記錄選項。`roleArn` 將 取代為您建立的記錄角色。

```
aws iotevents put-logging-options --cli-input-json "{ \"loggingOptions\": {\"roleArn\": \"arn:aws:iam::123456789012:role/testLoggingRole\", \"level\": \"INFO\", \"enabled\": true } }" 
```

# 的 Amazon SNS 訊息角色政策 AWS IoT Events
<a name="iotevents-permissions-sns"></a>

 AWS IoT Events 與 Amazon SNS 整合需要謹慎的許可管理，才能提供安全且有效率的通知。本指南會逐步引導您設定 IAM 角色和政策，以允許 AWS IoT Events 將訊息發佈至 Amazon SNS 主題。

下列政策文件提供允許 傳送 SNS 訊息的角色政策和信任政策 AWS IoT Events 。

角色政策：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": [
                "sns:*"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:sns:us-east-1:123456789012:testAction"
        }
    ]
}
```

------

信任政策：

------
#### [ JSON ]

****  

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

------