MediaPackage 使用範例 AWS CLI - AWS Command Line Interface

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

MediaPackage 使用範例 AWS CLI

下列程式碼範例說明如何使用 AWS Command Line Interface 與來執行動作及實作常見案例 MediaPackage。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境和跨服務範例中查看內容中的動作。

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

每個範例都包含一個連結 GitHub,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例會示範如何使用create-channel

AWS CLI

若要建立頻道

以下create-channel命令創建一個在當前帳戶sportschannel中命名的通道。

aws mediapackage create-channel --id sportschannel

輸出:

{ "Arn": "arn:aws:mediapackage:us-west-2:111222333:channels/6d345804ec3f46c9b454a91d4a80d0e0", "HlsIngest": { "IngestEndpoints": [ { "Id": "6d345804ec3f46c9b454a91d4a80d0e0", "Password": "generatedwebdavpassword1", "Url": "https://f31c86aed53b815a.mediapackage.us-west-2.amazonaws.com/in/v2/6d345804ec3f46c9b454a91d4a80d0e0/6d345804ec3f46c9b454a91d4a80d0e0/channel", "Username": "generatedwebdavusername1" }, { "Id": "2daa32878af24803b24183727211b8ff", "Password": "generatedwebdavpassword2", "Url": "https://6ebbe7e04c4b0afa.mediapackage.us-west-2.amazonaws.com/in/v2/6d345804ec3f46c9b454a91d4a80d0e0/2daa32878af24803b24183727211b8ff/channel", "Username": "generatedwebdavusername2" } ] }, "Id": "sportschannel", "Tags": { "region": "west" } }

若要取得更多資訊,請參閱《AWS 元素 MediaPackage 使用指南》中的〈建立頻道

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考CreateChannel中的。

下列程式碼範例會示範如何使用create-origin-endpoint

AWS CLI

建立原點端點

下列create-origin-endpoint命令會建立以 JSON 檔案中提cmafsports供的套件設定和指定端點設定命名的原始端點。

aws mediapackage create-origin-endpoint \ --channel-id sportschannel \ --id cmafsports \ --cmaf-package file://file/path/cmafpkg.json --description "cmaf output of sports" \ --id cmaf_sports \ --manifest-name sports_channel \ --startover-window-seconds 300 \ --tags region=west,media=sports \ --time-delay-seconds 10

輸出:

{ "Arn": "arn:aws:mediapackage:us-west-2:111222333:origin_endpoints/1dc6718be36f4f34bb9cd86bc50925e6", "ChannelId": "sportschannel", "CmafPackage": { "HlsManifests": [ { "AdMarkers": "PASSTHROUGH", "Id": "cmaf_sports_endpoint", "IncludeIframeOnlyStream": true, "ManifestName": "index", "PlaylistType": "EVENT", "PlaylistWindowSeconds": 300, "ProgramDateTimeIntervalSeconds": 300, "Url": "https://c4af3793bf76b33c.mediapackage.us-west-2.amazonaws.com/out/v1/1dc6718be36f4f34bb9cd86bc50925e6/cmaf_sports_endpoint/index.m3u8" } ], "SegmentDurationSeconds": 2, "SegmentPrefix": "sportschannel" }, "Description": "cmaf output of sports", "Id": "cmaf_sports", "ManifestName": "sports_channel", "StartoverWindowSeconds": 300, "Tags": { "region": "west", "media": "sports" }, "TimeDelaySeconds": 10, "Url": "", "Whitelist": [] }

若要取得更多資訊,請參閱《AWS 基本 MediaPackage 使用指南》中的〈建立端點

下列程式碼範例會示範如何使用delete-channel

AWS CLI

若要刪除頻道

下面的delete-channel命令刪除名為的通道test

aws mediapackage delete-channel \ --id test

此命令不會產生輸出。

若要取得更多資訊,請參閱《AWS 元素 MediaPackage 使用指南》中的〈刪除頻道

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DeleteChannel中的。

下列程式碼範例會示範如何使用delete-origin-endpoint

AWS CLI

刪除原點端點

下列delete-origin-endpoint指令會刪除名為的原點端點tester2

aws mediapackage delete-origin-endpoint \ --id tester2

若要取得更多資訊,請參閱《AWS 基本 MediaPackage 使用指南》中的〈刪除端點

下列程式碼範例會示範如何使用describe-channel

AWS CLI

若要描述頻道

下面的describe-channel命令顯示名為信道的所有細節test

aws mediapackage describe-channel \ --id test

輸出:

{ "Arn": "arn:aws:mediapackage:us-west-2:111222333:channels/584797f1740548c389a273585dd22a63", "HlsIngest": { "IngestEndpoints": [ { "Id": "584797f1740548c389a273585dd22a63", "Password": "webdavgeneratedpassword1", "Url": "https://9be9c4405c474882.mediapackage.us-west-2.amazonaws.com/in/v2/584797f1740548c389a273585dd22a63/584797f1740548c389a273585dd22a63/channel", "Username": "webdavgeneratedusername1" }, { "Id": "7d187c8616fd455f88aaa5a9fcf74442", "Password": "webdavgeneratedpassword2", "Url": "https://7bf454c57220328d.mediapackage.us-west-2.amazonaws.com/in/v2/584797f1740548c389a273585dd22a63/7d187c8616fd455f88aaa5a9fcf74442/channel", "Username": "webdavgeneratedusername2" } ] }, "Id": "test", "Tags": {} }

如需詳細資訊,請參閱《< https://docs.aws.amazon.com/mediapackage/latest/ug/channels-view.html > AWS 基本 MediaPackage 使用手冊》中的檢視頻道詳細資

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DescribeChannel中的。

下列程式碼範例會示範如何使用describe-origin-endpoint

AWS CLI

描述原點端點

下列describe-origin-endpoint指令會顯示名為的原始端點的所有詳細資料cmaf_sports

aws mediapackage describe-origin-endpoint \ --id cmaf_sports

輸出:

{ "Arn": "arn:aws:mediapackage:us-west-2:111222333:origin_endpoints/1dc6718be36f4f34bb9cd86bc50925e6", "ChannelId": "sportschannel", "CmafPackage": { "HlsManifests": [ { "AdMarkers": "NONE", "Id": "cmaf_sports_endpoint", "IncludeIframeOnlyStream": false, "PlaylistType": "EVENT", "PlaylistWindowSeconds": 60, "ProgramDateTimeIntervalSeconds": 0, "Url": "https://c4af3793bf76b33c.mediapackage.us-west-2.amazonaws.com/out/v1/1dc6718be36f4f34bb9cd86bc50925e6/cmaf_sports_endpoint/index.m3u8" } ], "SegmentDurationSeconds": 2, "SegmentPrefix": "sportschannel" }, "Id": "cmaf_sports", "ManifestName": "index", "StartoverWindowSeconds": 0, "Tags": { "region": "west", "media": "sports" }, "TimeDelaySeconds": 0, "Url": "", "Whitelist": [] }

若要取得更多資訊,請參閱《AWS 基本 MediaPackage 使用指南》中的〈檢視單一端點

下列程式碼範例會示範如何使用list-channels

AWS CLI

列出所有頻道

以下list-channels命令列出了當前 AWS 帳戶上配置的所有通道。

aws mediapackage list-channels

輸出:

{ "Channels": [ { "Arn": "arn:aws:mediapackage:us-west-2:111222333:channels/584797f1740548c389a273585dd22a63", "HlsIngest": { "IngestEndpoints": [ { "Id": "584797f1740548c389a273585dd22a63", "Password": "webdavgeneratedpassword1", "Url": "https://9be9c4405c474882.mediapackage.us-west-2.amazonaws.com/in/v2/584797f1740548c389a273585dd22a63/584797f1740548c389a273585dd22a63/channel", "Username": "webdavgeneratedusername1" }, { "Id": "7d187c8616fd455f88aaa5a9fcf74442", "Password": "webdavgeneratedpassword2", "Url": "https://7bf454c57220328d.mediapackage.us-west-2.amazonaws.com/in/v2/584797f1740548c389a273585dd22a63/7d187c8616fd455f88aaa5a9fcf74442/channel", "Username": "webdavgeneratedusername2" } ] }, "Id": "test", "Tags": {} } ] }

如需詳細資訊,請參閱《AWS 基本 MediaPackage 使用指南》中的檢視頻道詳細資料。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListChannels中的。

下列程式碼範例會示範如何使用list-origin-endpoints

AWS CLI

列出頻道上的所有起點端點

下列list-origin-endpoints指令會列出在名稱為的通道上設定的所有原始端點test

aws mediapackage list-origin-endpoints \ --channel-id test

輸出:

{ "OriginEndpoints": [ { "Arn": "arn:aws:mediapackage:us-west-2:111222333:origin_endpoints/247cff871f2845d3805129be22f2c0a2", "ChannelId": "test", "DashPackage": { "ManifestLayout": "FULL", "ManifestWindowSeconds": 60, "MinBufferTimeSeconds": 30, "MinUpdatePeriodSeconds": 15, "PeriodTriggers": [], "Profile": "NONE", "SegmentDurationSeconds": 2, "SegmentTemplateFormat": "NUMBER_WITH_TIMELINE", "StreamSelection": { "MaxVideoBitsPerSecond": 2147483647, "MinVideoBitsPerSecond": 0, "StreamOrder": "ORIGINAL" }, "SuggestedPresentationDelaySeconds": 25 }, "Id": "tester2", "ManifestName": "index", "StartoverWindowSeconds": 0, "Tags": {}, "TimeDelaySeconds": 0, "Url": "https://8343f7014c0ea438.mediapackage.us-west-2.amazonaws.com/out/v1/247cff871f2845d3805129be22f2c0a2/index.mpd", "Whitelist": [] }, { "Arn": "arn:aws:mediapackage:us-west-2:111222333:origin_endpoints/869e237f851549e9bcf10e3bc2830839", "ChannelId": "test", "HlsPackage": { "AdMarkers": "NONE", "IncludeIframeOnlyStream": false, "PlaylistType": "EVENT", "PlaylistWindowSeconds": 60, "ProgramDateTimeIntervalSeconds": 0, "SegmentDurationSeconds": 6, "StreamSelection": { "MaxVideoBitsPerSecond": 2147483647, "MinVideoBitsPerSecond": 0, "StreamOrder": "ORIGINAL" }, "UseAudioRenditionGroup": false }, "Id": "tester", "ManifestName": "index", "StartoverWindowSeconds": 0, "Tags": {}, "TimeDelaySeconds": 0, "Url": "https://8343f7014c0ea438.mediapackage.us-west-2.amazonaws.com/out/v1/869e237f851549e9bcf10e3bc2830839/index.m3u8", "Whitelist": [] } ] }

如需詳細資訊,請參閱《AWS 基本 MediaPackage 使用指南》中的〈檢視與通道相關聯的所有端點

下列程式碼範例會示範如何使用list-tags-for-resource

AWS CLI

若要列出指定給資源的標籤

以下list-tags-for-resource命令列出了分配給指定資源的標籤。

aws mediapackage list-tags-for-resource \ --resource-arn arn:aws:mediapackage:us-west-2:111222333:channels/6d345804ec3f46c9b454a91d4a80d0e0

輸出:

{ "Tags": { "region": "west" } }

若要取得更多資訊,請參閱《 AWS 元素 MediaPackage 使用指南》 MediaPackage中的〈標記AWS 元素中的資源

下列程式碼範例會示範如何使用rotate-ingest-endpoint-credentials

AWS CLI

若要旋轉擷取認證

下列rotate-ingest-endpoint-credentials命令會為指定的擷取端點旋轉 WebDAV 使用者名稱和密碼。

aws mediapackage rotate-ingest-endpoint-credentials \ --id test \ --ingest-endpoint-id 584797f1740548c389a273585dd22a63

輸出:

{ "Arn": "arn:aws:mediapackage:us-west-2:111222333:channels/584797f1740548c389a273585dd22a63", "HlsIngest": { "IngestEndpoints": [ { "Id": "584797f1740548c389a273585dd22a63", "Password": "webdavregeneratedpassword1", "Url": "https://9be9c4405c474882.mediapackage.us-west-2.amazonaws.com/in/v2/584797f1740548c389a273585dd22a63/584797f1740548c389a273585dd22a63/channel", "Username": "webdavregeneratedusername1" }, { "Id": "7d187c8616fd455f88aaa5a9fcf74442", "Password": "webdavgeneratedpassword2", "Url": "https://7bf454c57220328d.mediapackage.us-west-2.amazonaws.com/in/v2/584797f1740548c389a273585dd22a63/7d187c8616fd455f88aaa5a9fcf74442/channel", "Username": "webdavgeneratedusername2" } ] }, "Id": "test", "Tags": {} }

如需詳細資訊,請參閱《AWS 基本 MediaPackage 使用指南》中的〈在輸入 URL 上輪換身分證明

下列程式碼範例會示範如何使用tag-resource

AWS CLI

將標籤加入資源

下列tag-resource命令會將region=west索引鍵和值配對新增至指定的資源。

aws mediapackage tag-resource \ --resource-arn arn:aws:mediapackage:us-west-2:111222333:channels/6d345804ec3f46c9b454a91d4a80d0e0 \ --tags region=west

此命令不會產生輸出。

若要取得更多資訊,請參閱《 AWS 元素 MediaPackage 使用指南》 MediaPackage中的〈標記AWS 元素中的資源

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考TagResource中的。

下列程式碼範例會示範如何使用untag-resource

AWS CLI

若要從資源中移除標籤

以下untag-resource命令從指定的通道region中刪除帶有密鑰的標籤。

aws mediapackage untag-resource \ --resource-arn arn:aws:mediapackage:us-west-2:111222333:channels/6d345804ec3f46c9b454a91d4a80d0e0 \ --tag-keys region

若要取得更多資訊,請參閱《 AWS 元素 MediaPackage 使用指南》 MediaPackage中的〈標記AWS 元素中的資源

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考UntagResource中的。

下列程式碼範例會示範如何使用update-channel

AWS CLI

若要更新頻道

下列update-channel指令會更新名為的頻道,sportschannel以包含描述24x7 sports

aws mediapackage update-channel \ --id sportschannel \ --description "24x7 sports"

輸出:

{ "Arn": "arn:aws:mediapackage:us-west-2:111222333:channels/6d345804ec3f46c9b454a91d4a80d0e0", "Description": "24x7 sports", "HlsIngest": { "IngestEndpoints": [ { "Id": "6d345804ec3f46c9b454a91d4a80d0e0", "Password": "generatedwebdavpassword1", "Url": "https://f31c86aed53b815a.mediapackage.us-west-2.amazonaws.com/in/v2/6d345804ec3f46c9b454a91d4a80d0e0/6d345804ec3f46c9b454a91d4a80d0e0/channel", "Username": "generatedwebdavusername1" }, { "Id": "2daa32878af24803b24183727211b8ff", "Password": "generatedwebdavpassword2", "Url": "https://6ebbe7e04c4b0afa.mediapackage.us-west-2.amazonaws.com/in/v2/6d345804ec3f46c9b454a91d4a80d0e0/2daa32878af24803b24183727211b8ff/channel", "Username": "generatedwebdavusername2" } ] }, "Id": "sportschannel", "Tags": {} }

若要取得更多資訊,請參閱《AWS 元素 MediaPackage 使用指南》中的〈編輯頻道

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考UpdateChannel中的。

下列程式碼範例會示範如何使用update-origin-endpoint

AWS CLI

更新原點端點

下列update-origin-endpoint指令會更新名為的原點端點cmaf_sports。它將時間延遲更改為0秒。

aws mediapackage update-origin-endpoint \ --id cmaf_sports \ --time-delay-seconds 0

輸出:

{ "Arn": "arn:aws:mediapackage:us-west-2:111222333:origin_endpoints/1dc6718be36f4f34bb9cd86bc50925e6", "ChannelId": "sportschannel", "CmafPackage": { "HlsManifests": [ { "AdMarkers": "NONE", "Id": "cmaf_sports_endpoint", "IncludeIframeOnlyStream": false, "PlaylistType": "EVENT", "PlaylistWindowSeconds": 60, "ProgramDateTimeIntervalSeconds": 0, "Url": "https://c4af3793bf76b33c.mediapackage.us-west-2.amazonaws.com/out/v1/1dc6718be36f4f34bb9cd86bc50925e6/cmaf_sports_endpoint/index.m3u8" } ], "SegmentDurationSeconds": 2, "SegmentPrefix": "sportschannel" }, "Id": "cmaf_sports", "ManifestName": "index", "StartoverWindowSeconds": 0, "Tags": { "region": "west", "media": "sports" }, "TimeDelaySeconds": 0, "Url": "", "Whitelist": [] }

若要取得更多資訊,請參閱《AWS 基本 MediaPackage 使用指南》中的〈編輯端點