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

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

MediaConnect 範例使用 AWS CLI

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

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

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

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

主題

動作

下列程式碼範例會示範如何使用add-flow-outputs

AWS CLI

若要將輸出新增至流程

下列add-flow-outputs範例會將輸出新增至指定流程。

aws mediaconnect add-flow-outputs \ --flow-arn arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame \ --outputs Description='NYC stream',Destination=192.0.2.12,Name=NYC,Port=3333,Protocol=rtp-fec,SmoothingLatency=100 Description='LA stream',Destination=203.0.113.9,Name=LA,Port=4444,Protocol=rtp-fec,SmoothingLatency=100

輸出:

{ "Outputs": [ { "Port": 3333, "OutputArn": "arn:aws:mediaconnect:us-east-1:111122223333:output:2-3aBC45dEF67hiJ89-c34de5fG678h:NYC", "Name": "NYC", "Description": "NYC stream", "Destination": "192.0.2.12", "Transport": { "Protocol": "rtp-fec", "SmoothingLatency": 100 } }, { "Port": 4444, "OutputArn": "arn:aws:mediaconnect:us-east-1:111122223333:output:2-987655dEF67hiJ89-c34de5fG678h:LA", "Name": "LA", "Description": "LA stream", "Destination": "203.0.113.9", "Transport": { "Protocol": "rtp-fec", "SmoothingLatency": 100 } } ], "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame" }

若要取得更多資訊,請參閱《AWS 元素 MediaConnect 使用指南》中的〈將輸出加入至流程

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

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

AWS CLI

建立流程的步驟

下列create-flow範例會使用指定的組態建立流程。

aws mediaconnect create-flow \ --availability-zone us-west-2c \ --name ExampleFlow \ --source Description='Example source, backup',IngestPort=1055,Name=BackupSource,Protocol=rtp,WhitelistCidr=10.24.34.0/23

輸出:

{ "Flow": { "FlowArn": "arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:ExampleFlow", "AvailabilityZone": "us-west-2c", "EgressIp": "54.245.71.21", "Source": { "IngestPort": 1055, "SourceArn": "arn:aws:mediaconnect:us-east-1:123456789012:source:2-3aBC45dEF67hiJ89-c34de5fG678h:BackupSource", "Transport": { "Protocol": "rtp", "MaxBitrate": 80000000 }, "Description": "Example source, backup", "IngestIp": "54.245.71.21", "WhitelistCidr": "10.24.34.0/23", "Name": "mySource" }, "Entitlements": [], "Name": "ExampleFlow", "Outputs": [], "Status": "STANDBY", "Description": "Example source, backup" } }

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

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

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

AWS CLI

若要刪除流程

下列delete-flow範例會刪除指定的流程。

aws mediaconnect delete-flow \ --flow-arn arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow

輸出:

{ "FlowArn": "arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow", "Status": "DELETING" }

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

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

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

AWS CLI

若要檢視流程的詳細資訊

下列describe-flow範例顯示指定流程的詳細資料,例如 ARN、可用區域、狀態、來源、權利和輸出。

aws mediaconnect describe-flow \ --flow-arn arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow

輸出:

{ "Flow": { "EgressIp": "54.201.4.39", "AvailabilityZone": "us-west-2c", "Status": "ACTIVE", "FlowArn": "arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow", "Entitlements": [ { "EntitlementArn": "arn:aws:mediaconnect:us-west-2:123456789012:entitlement:1-AaBb11CcDd22EeFf-34DE5fG12AbC:MyEntitlement", "Description": "Assign to this account", "Name": "MyEntitlement", "Subscribers": [ "444455556666" ] } ], "Description": "NYC awards show", "Name": "AwardsShow", "Outputs": [ { "Port": 2355, "Name": "NYC", "Transport": { "SmoothingLatency": 0, "Protocol": "rtp-fec" }, "OutputArn": "arn:aws:mediaconnect:us-east-1:123456789012:output:2-3aBC45dEF67hiJ89-c34de5fG678h:NYC", "Destination": "192.0.2.0" }, { "Port": 3025, "Name": "LA", "Transport": { "SmoothingLatency": 0, "Protocol": "rtp-fec" }, "OutputArn": "arn:aws:mediaconnect:us-east-1:123456789012:output:2-987655dEF67hiJ89-c34de5fG678h:LA", "Destination": "192.0.2.0" } ], "Source": { "IngestIp": "54.201.4.39", "SourceArn": "arn:aws:mediaconnect:us-east-1:123456789012:source:3-4aBC56dEF78hiJ90-4de5fG6Hi78Jk:ShowSource", "Transport": { "MaxBitrate": 80000000, "Protocol": "rtp" }, "IngestPort": 1069, "Description": "Saturday night show", "Name": "ShowSource", "WhitelistCidr": "10.24.34.0/23" } } }

如需詳細資訊,請參閱《AWS 基本 MediaConnect 使用指南》中的〈檢視流程明細〉

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

下列程式碼範例會示範如何使用grant-flow-entitlements

AWS CLI

授與流程的權利

下列grant-flow-entitlements範例會授予指定現有流程的權利,以便與其他 AWS 帳戶共用您的內容。

aws mediaconnect grant-flow-entitlements \ --flow-arn arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame \ --entitlements Description='For AnyCompany',Encryption={"Algorithm=aes128,KeyType=static-key,RoleArn=arn:aws:iam::111122223333:role/MediaConnect-ASM,SecretArn=arn:aws:secretsmanager:us-west-2:111122223333:secret:mySecret1"},Name=AnyCompany_Entitlement,Subscribers=444455556666 Description='For Example Corp',Name=ExampleCorp,Subscribers=777788889999

輸出:

{ "Entitlements": [ { "Name": "AnyCompany_Entitlement", "EntitlementArn": "arn:aws:mediaconnect:us-west-2:111122223333:entitlement:1-11aa22bb11aa22bb-3333cccc4444:AnyCompany_Entitlement", "Subscribers": [ "444455556666" ], "Description": "For AnyCompany", "Encryption": { "SecretArn": "arn:aws:secretsmanager:us-west-2:111122223333:secret:mySecret1", "Algorithm": "aes128", "RoleArn": "arn:aws:iam::111122223333:role/MediaConnect-ASM", "KeyType": "static-key" } }, { "Name": "ExampleCorp", "EntitlementArn": "arn:aws:mediaconnect:us-west-2:111122223333:entitlement:1-3333cccc4444dddd-1111aaaa2222:ExampleCorp", "Subscribers": [ "777788889999" ], "Description": "For Example Corp" } ], "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame" }

有關詳情,請參閱《AWS 基本 MediaConnect 使用者指南》的授與流程的軟體權利文件

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

AWS CLI

檢視權利清單

下列list-entitlements範例會顯示已授與帳戶的所有權利清單。

aws mediaconnect list-entitlements

輸出:

{ "Entitlements": [ { "EntitlementArn": "arn:aws:mediaconnect:us-west-2:111122223333:entitlement:1-11aa22bb11aa22bb-3333cccc4444:MyEntitlement", "EntitlementName": "MyEntitlement" } ] }

如需詳細資訊,請參閱AWS 基本 MediaConnect API 參考ListEntitlements中的。

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

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

AWS CLI

若要檢視流程清單

下列list-flows範例顯示流程清單。

aws mediaconnect list-flows

輸出:

{ "Flows": [ { "Status": "STANDBY", "SourceType": "OWNED", "AvailabilityZone": "us-west-2a", "Description": "NYC awards show", "Name": "AwardsShow", "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow" }, { "Status": "STANDBY", "SourceType": "OWNED", "AvailabilityZone": "us-west-2c", "Description": "LA basketball game", "Name": "BasketballGame", "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BasketballGame" } ] }

若要取得更多資訊,請參閱《AWS 基本 MediaConnect 使用指南》中的〈檢視流程清單

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

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

AWS CLI

若要列出 MediaConnect 資源的標籤

下列list-tags-for-resource範例會顯示與指定 MediaConnect 資源相關聯的標籤索引鍵和值。

aws mediaconnect list-tags-for-resource \ --resource-arn arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BasketballGame

輸出:

{ "Tags": { "region": "west", "stage": "prod" } }

如需詳細資訊 ListTagsForResource TagResource,請參閱〈AWS 元素 MediaConnect API 參考〉 UntagResource中的〈〉。

下列程式碼範例會示範如何使用remove-flow-output

AWS CLI

若要從流程中移除輸出

下列remove-flow-output範例會從指定流程中移除輸出。

aws mediaconnect remove-flow-output \ --flow-arn arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame \ --output-arn arn:aws:mediaconnect:us-east-1:111122223333:output:2-3aBC45dEF67hiJ89-c34de5fG678h:NYC

輸出:

{ "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame", "OutputArn": "arn:aws:mediaconnect:us-east-1:111122223333:output:2-3aBC45dEF67hiJ89-c34de5fG678h:NYC" }

若要取得更多資訊,請參閱《AWS 元素 MediaConnect 使用指南》中的〈移除流程中的輸出

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

下列程式碼範例會示範如何使用revoke-flow-entitlement

AWS CLI

撤銷權利

下列revoke-flow-entitlement範例會撤銷指定流程上的軟體權利文件。

aws mediaconnect revoke-flow-entitlement \ --flow-arn arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame \ --entitlement-arn arn:aws:mediaconnect:us-west-2:111122223333:entitlement:1-11aa22bb11aa22bb-3333cccc4444:AnyCompany_Entitlement

輸出:

{ "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame", "EntitlementArn": "arn:aws:mediaconnect:us-west-2:111122223333:entitlement:1-11aa22bb11aa22bb-3333cccc4444:AnyCompany_Entitlement" }

如需詳細資訊,請參閱《AWS 基本 MediaConnect 使用手冊》中的撤銷軟體權利文件

下列程式碼範例會示範如何使用start-flow

AWS CLI

啟動流程的步驟

下列start-flow範例會啟動指定的流程。

aws mediaconnect start-flow \ --flow-arn arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow

此命令不會產生輸出。輸出:

{ "FlowArn": "arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow", "Status": "STARTING" }

若要取得更多資訊,請參閱《AWS 基本 MediaConnect 使用指南》中的〈啟動流程

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

下列程式碼範例會示範如何使用stop-flow

AWS CLI

停止流程的步驟

下列stop-flow範例會停止指定的流程。

aws mediaconnect stop-flow \ --flow-arn arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow

輸出:

{ "Status": "STOPPING", "FlowArn": "arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow" }

若要取得更多資訊,請參閱《AWS 基本 MediaConnect 使用指南》中的〈停止流程

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

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

AWS CLI

若要將標籤新增至 MediaConnect 資源

下列tag-resource範例會將含有索引鍵名稱和值的標籤新增至指定的 MediaConnect 資源。

aws mediaconnect tag-resource \ --resource-arn arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BasketballGame --tags region=west

此命令不會產生輸出。

如需詳細資訊 ListTagsForResource TagResource,請參閱〈AWS 元素 MediaConnect API 參考〉 UntagResource中的〈〉。

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

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

AWS CLI

若要從 MediaConnect 資源中移除標籤

下列untag-resource範例會從 MediaConnect 資源中移除具有指定索引鍵名稱及其關聯值的標籤。

aws mediaconnect untag-resource \ --resource-arn arn:aws:mediaconnect:us-east-1:123456789012:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BasketballGame \ --tag-keys region

此命令不會產生輸出。

如需詳細資訊 ListTagsForResource TagResource,請參閱〈AWS 元素 MediaConnect API 參考〉 UntagResource中的〈〉。

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

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

AWS CLI

更新軟體權利文件

下列update-flow-entitlement範例會使用新的說明和訂閱者來更新指定的權利。

aws mediaconnect update-flow-entitlement \ --flow-arn arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame \ --entitlement-arn arn:aws:mediaconnect:us-west-2:111122223333:entitlement:1-11aa22bb11aa22bb-3333cccc4444:AnyCompany_Entitlement \ --description 'For AnyCompany Affiliate' \ --subscribers 777788889999

輸出:

{ "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame", "Entitlement": { "Name": "AnyCompany_Entitlement", "Description": "For AnyCompany Affiliate", "EntitlementArn": "arn:aws:mediaconnect:us-west-2:111122223333:entitlement:1-11aa22bb11aa22bb-3333cccc4444:AnyCompany_Entitlement", "Encryption": { "KeyType": "static-key", "Algorithm": "aes128", "RoleArn": "arn:aws:iam::111122223333:role/MediaConnect-ASM", "SecretArn": "arn:aws:secretsmanager:us-west-2:111122223333:secret:mySecret1" }, "Subscribers": [ "777788889999" ] } }

如需詳細資訊,請參閱AWS 基本 MediaConnect 使用指南中的更新軟體權利文件

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

AWS CLI

若要更新流程的輸出

下列update-flow-output範例會更新指定流程上的輸出。

aws mediaconnect update-flow-output \ --flow-arn arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame \ --output-arn arn:aws:mediaconnect:us-east-1:111122223333:output:2-3aBC45dEF67hiJ89-c34de5fG678h:NYC \ --port 3331

輸出:

{ "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:BaseballGame", "Output": { "Name": "NYC", "Port": 3331, "Description": "NYC stream", "Transport": { "Protocol": "rtp-fec", "SmoothingLatency": 100 }, "OutputArn": "arn:aws:mediaconnect:us-east-1:111122223333:output:2-3aBC45dEF67hiJ89-c34de5fG678h:NYC", "Destination": "192.0.2.12" } }

若要取得更多資訊,請參閱《AWS 基本 MediaConnect 使用指南》中的〈更新流程的輸出

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

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

AWS CLI

若要更新現有流程的來源

下列update-flow-source範例會更新現有流程的來源。

aws mediaconnect update-flow-source \ --flow-arn arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow \ --source-arn arn:aws:mediaconnect:us-east-1:111122223333:source:3-4aBC56dEF78hiJ90-4de5fG6Hi78Jk:ShowSource \ --description 'Friday night show' \ --ingest-port 3344 \ --protocol rtp-fec \ --whitelist-cidr 10.24.34.0/23

輸出:

{ "FlowArn": "arn:aws:mediaconnect:us-east-1:111122223333:flow:1-23aBC45dEF67hiJ8-12AbC34DE5fG:AwardsShow", "Source": { "IngestIp": "34.210.136.56", "WhitelistCidr": "10.24.34.0/23", "Transport": { "Protocol": "rtp-fec" }, "IngestPort": 3344, "Name": "ShowSource", "Description": "Friday night show", "SourceArn": "arn:aws:mediaconnect:us-east-1:111122223333:source:3-4aBC56dEF78hiJ90-4de5fG6Hi78Jk:ShowSource" } }

如需詳細資訊,請參閱《AWS 基本 MediaConnect 使用指南》中的〈更新流程來源

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