

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

# 在 AWS 雲端中管理串流
<a name="mqtt-based-file-delivery-managing"></a>

AWS IoT 提供 AWS SDK 和 AWS CLI 命令，您可以用來管理 AWS 雲端中的串流。您可使用這些命令來執行下列：
+ 建立串流 [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 或 AWS SDK 來管理 中的串流 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 雲端 AWS IoT 中與 整合，因此您的裝置應該直接連線至[AWS IoT 資料平面的端點](https://docs.aws.amazon.com//iot/latest/apireference/Welcome.html#Welcome_AWS_IoT_Data_Plane)。

**注意**  
 AWS IoT 資料平面的端點專屬於 AWS 帳戶 和 區域。您必須將 端點用於裝置註冊所在的 AWS 帳戶 和 區域 AWS IoT。

如需詳細資訊，請參閱[連線至 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`，`AccessDeniedException`如果請求隨附標籤，`CreateStream`API 呼叫將傳回 。

如需詳細資訊，請參閱下列連結：
+ [CreateStream](https://docs.aws.amazon.com//iot/latest/apireference/API_CreateStream.html)
+ [TagResource](https://docs.aws.amazon.com//iot/latest/apireference/API_TagResource.html)
+ [標籤](https://docs.aws.amazon.com//iot/latest/apireference/API_Tag.html)