

终止支持通知：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/注册。](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，启用并创建管理用户，这样您就不会使用 root 用户执行日常任务。

**保护你的 AWS 账户根用户**

1.  选择 **Root 用户**并输入您的 AWS 账户 电子邮件地址，以账户所有者的身份登录。[AWS 管理控制台](https://console.aws.amazon.com/)在下一页上，输入您的密码。

   要获取使用根用户登录方面的帮助，请参阅《AWS 登录 用户指南》**中的 [Signing in as the root user](https://docs.aws.amazon.com/signin/latest/userguide/console-sign-in-tutorials.html#introduction-to-root-user-sign-in-tutorial)。

1. 为您的根用户启用多重身份验证（MFA）。

   有关说明，请参阅 I [A *M* 用户指南中的为 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 目录 作为身份源的教程，请参阅《[用户*指南》 IAM Identity Center 目录中的使用默认设置配置AWS 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 用户指南》**中的 [Create a permission set](https://docs.aws.amazon.com//singlesignon/latest/userguide/get-started-create-a-permission-set.html)。

1. 将用户分配到一个组，然后为该组分配单点登录访问权限。

   有关说明，请参阅《AWS IAM Identity Center 用户指南》**中的 [Add groups](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。

I [AM 用户指南](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 权限。本节包含操作列表和示例策略，该策略授权对您的资源执行所有此类操作。根据需要更改*region*和*account-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) 发布有关 MATT 主题的消息。
+ [`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 Policy**    
****  

```
{
    "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 资源名称 (ARNs) 列表，而不是通配符 `*` “”，从而将此权限限制为特定输入。`Resource`这可以让您限制对探测器模型使用并由用户或实体创建或更新的输入数据的访问权限。

# 适用于 Amazon 的 CloudWatch 日志角色政策 AWS IoT Events
<a name="iotevents-permissions-cloudwatch"></a>

以下策略文件提供了允许代表您向 CloudWatch 其提交日志 AWS IoT Events 的角色策略和信任策略。

角色策略：

------
#### [ 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 权限策略，以允许该用户按以下方式传递角色。有关更多信息，请参阅 *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 主题发布消息的过程。

以下策略文档提供了角色策略和信任策略，它们可以让 AWS IoT Events 发送 SNS 消息。

角色策略：

------
#### [ 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"
    }
  ]
}
```

------