

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 AWS 云端管理直播
<a name="mqtt-based-file-delivery-managing"></a>

AWS IoT 提供可用于管理 AWS 云端直播的 AWS SDK 和 AWS CLI 命令。您可以使用这些命令来进行以下操作：
+ 创建流。[CLI](https://docs.aws.amazon.com//cli/latest/reference/iot/create-stream.html) / [SDK](https://docs.aws.amazon.com//iot/latest/apireference/API_CreateStream.html)
+ 描述流以获取其信息。[CLI](https://docs.aws.amazon.com//cli/latest/reference/iot/describe-stream.html) / [SDK](https://docs.aws.amazon.com//iot/latest/apireference/API_DescribeStream.html)
+ 列出你中的直播 AWS 账户. [CLI](https://docs.aws.amazon.com//cli/latest/reference/iot/list-streams.html) / [SDK](https://docs.aws.amazon.com//iot/latest/apireference/API_ListStreams.html)
+ 更新流中的文件列表或流描述。[CLI](https://docs.aws.amazon.com//cli/latest/reference/iot/update-stream.html) / [SDK](https://docs.aws.amazon.com//iot/latest/apireference/API_UpdateStream.html)
+ 删除流。[CLI](https://docs.aws.amazon.com//cli/latest/reference/iot/delete-stream.html) / [SDK](https://docs.aws.amazon.com//iot/latest/apireference/API_DeleteStream.html)

**注意**  
此时，流在 AWS 管理控制台中不可见。您必须使用 AWS CLI 或 S AWS DK 来管理中的直播 AWS IoT。此外，[嵌入式 C SDK](https://github.com/aws/aws-iot-device-sdk-embedded-C) 是唯一支持基于 MQTT 的文件传输功能的 SDK。

在您的设备上使用 AWS IoT 基于 MQTT 的文件传输之前，必须确保您的设备满足以下条件，如下一节所示：
+ 反映通过 MQTT 传输数据所需的正确权限的策略。
+ 您的设备可以连接到 AWS IoT 设备网关。
+ 声明您可以为资源添加标签的策略声明。如果使用标签调用 `CreateStream`，则需要 `iot:TagResource`。

在设备上使用 AWS IoT 基于 MQTT 的文件传输之前，必须按照下一节中的步骤进行操作，以确保您的设备已获得适当的授权并且可以连接到 AWS IoT 设备网关。

## 向您的设备授予权限
<a name="mqtt-based-file-delivery-permissions"></a>

您可以按照[创建 AWS IoT 策略](https://docs.aws.amazon.com//iot/latest/developerguide/create-iot-resources.html#create-iot-policy)中的步骤创建设备策略，或使用现有设备策略。将策略附加到与您的设备关联的证书，并将以下权限添加到设备策略中。

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iot:Connect"
            ],
            "Resource": [
            "arn:aws:iot:us-east-1:123456789012:client/${iot:Connection.Thing.ThingName}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "iot:Receive",
                "iot:Publish"
            ],
            "Resource": [
            "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/${iot:Connection.Thing.ThingName}/streams/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "iot:Subscribe",
            "Resource": [
            "arn:aws:iot:us-east-1:123456789012:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/streams/*"
            ]
        }
    ]
}
```

## 将您的设备连接到 AWS IoT
<a name="mqtt-based-file-delivery-connect-devices"></a>

使用 AWS IoT 基于 MQTT 的文件传输的设备需要连接。 AWS IoT AWS IoT 基于 MQTT 的文件传输与 AWS IoT AWS 云端集成，因此您的设备应直接连接到[AWS IoT 数据平面的端点](https://docs.aws.amazon.com//iot/latest/apireference/Welcome.html#Welcome_AWS_IoT_Data_Plane)。

**注意**  
 AWS IoT 数据平面的端点特定于 AWS 账户 和区域。您必须使用设备注册所在地区的终端节点 AWS IoT。 AWS 账户 

请参阅[连接到 AWS IoT Core](connect-to-iot.md)了解更多信息。

## TagResource 用法
<a name="mqtt-based-file-delivery-tag-resource"></a>

`CreateStream` API 操作将创建一个流，以便通过 MQTT 以分块形式传送一个或多个大文件。

成功的 `CreateStream` API 调用需要以下权限：
+ `iot:CreateStream`
+ `iot:TagResource`（如果 `CreateStream` 带有标签）

支持这两个权限的策略如下所示：

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Action": [
            "iot:CreateStream",
            "iot:TagResource"
        ],
        "Effect": "Allow",
        "Resource": "arn:aws:iot:us-east-1:123456789012:stream/streamId"
    }
}
```

为确保用户在没有适当权限的情况下无法在资源上创建或更新标签，需要 `iot:TagResource` 策略声明操作。没有具体的 `iot:TagResource` 策略声明操作，`CreateStream` API 调用将返回 `AccessDeniedException`（如果请求附带标签）。

有关更多信息，请参阅以下链接：
+ [CreateStream](https://docs.aws.amazon.com//iot/latest/apireference/API_CreateStream.html)
+ [TagResource](https://docs.aws.amazon.com//iot/latest/apireference/API_TagResource.html)
+ [Tag](https://docs.aws.amazon.com//iot/latest/apireference/API_Tag.html)