使用 的 MediaConnect 範例 AWS CLI - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

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

使用 的 MediaConnect 範例 AWS CLI

下列程式碼範例示範如何使用 AWS Command Line Interface with MediaConnect 來執行動作和實作常見案例。

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

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

主題

動作

下列程式碼範例示範如何使用 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 Elemental 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 Elemental 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 Elemental 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 Elemental 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 Elemental 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" } ] }

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

  • 如需 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 Elemental MediaConnect 使用者指南中的檢視流程清單

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

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

AWS CLI

列出 a 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" } }

如需詳細資訊,請參閱 ElementalWord UntagResource 參考中的 ListTagsForResource、 TagResource、Word。 AWS MediaConnect API

下列程式碼範例示範如何使用 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 Elemental 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 Elemental 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 Elemental 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 Elemental MediaConnect 使用者指南中的停止流程

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

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

AWS CLI

將標籤新增至 a 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

此命令不會產生輸出。

如需詳細資訊,請參閱 Elemental TagResource UntagResourceWord 參考中的 ListTagsForResource、Word、Word。 AWS MediaConnect API

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

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

AWS CLI

從 a MediaConnect 資源中移除標籤

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

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

此命令不會產生輸出。

如需詳細資訊,請參閱 Elemental TagResource UntagResourceWord 參考中的 ListTagsForResource、Word、Word。 AWS MediaConnect API

  • 如需 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 Elemental 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 Elemental 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 Elemental MediaConnect 使用者指南中的更新流程來源

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