Amazon IVS 示例使用 AWS CLI - AWS Command Line Interface

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

Amazon IVS 示例使用 AWS CLI

下列程式碼範例說明如何透過 AWS Command Line Interface 搭配 Amazon IVS 使用來執行動作和實作常見案例。

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

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

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

主題

動作

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

AWS CLI

若要取得有關多個通道的頻道組態資訊

下列batch-get-channel範例會列出指定頻道的相關資訊。

aws ivs batch-get-channel \ --arns arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh \ arn:aws:ivs:us-west-2:123456789012:channel/efghEFGHijkl

輸出:

{ "channels": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "authorized": false, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": false, "latencyMode": "LOW", "name": "channel-1", "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel-1.abcdEFGH.m3u8", "preset": "", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2defGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "tags": {}, "type": "STANDARD" }, { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/efghEFGHijkl", "authorized": false, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": true, "latencyMode": "LOW", "name": "channel-2", "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel-2.abcdEFGH.m3u8", "preset": "", "playbackRestrictionPolicyArn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ"", "recordingConfigurationArn": "", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "BA1C2defGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "tags": {}, "type": "STANDARD" } ] }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

下列程式碼範例會示範如何使用batch-get-stream-key

AWS CLI

取得多個串流金鑰的相關資訊

下列batch-get-stream-key範例會取得指定串流金鑰的相關資訊。

aws ivs batch-get-stream-key \ --arns arn:aws:ivs:us-west-2:123456789012:stream-key/skSKABCDefgh \ arn:aws:ivs:us-west-2:123456789012:stream-key/skSKIJKLmnop

輸出:

{ "streamKeys": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/skSKABCDefgh", "value": "sk_us-west-2_abcdABCDefgh_567890abcdef", "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "tags": {} }, { "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/skSKIJKLmnop", "value": "sk_us-west-2_abcdABCDefgh_567890ghijkl", "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "tags": {} } ] }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

下列程式碼範例會示範如何使用batch-start-viewer-session-revocation

AWS CLI

撤銷多個通道 ARN 和檢視器 ID 配對的檢視器工作階段

下列batch-start-viewer-session-revocation範例會同時針對多個通道 ARN 和檢視器 ID 配對執行階段作業撤銷。請求可能會正常完成,但如果調用者沒有撤銷指定會話的權限,則返回錯誤字段中的值。

aws ivs batch-start-viewer-session-revocation \ --viewer-sessions '[{"channelArn":"arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh1","viewerId":"abcdefg1","viewerSessionVersionsLessThanOrEqualTo":1234567890}, \ {"channelArn":"arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh2","viewerId":"abcdefg2","viewerSessionVersionsLessThanOrEqualTo":1234567890}]'

輸出:

{ "errors": [ { "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh1", "viewerId": "abcdefg1", "code": "403", "message": "not authorized", }, { "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh2", "viewerId": "abcdefg2", "code": "403", "message": "not authorized", } ] }

如需詳細資訊,請參閱《Amazon 互動式影片服務使用者指南》中的設定私有頻道

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

AWS CLI

範例 1:建立沒有錄製的頻道

下列create-channel範例會建立新頻道和關聯的串流金鑰,以開始串流。

aws ivs create-channel \ --name "test-channel" \ --no-insecure-ingest

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "authorized": false, "name": "test-channel", "latencyMode": "LOW", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2defGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": false, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "preset": "", "tags": {}, "type": "STANDARD" }, "streamKey": { "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/g1H2I3j4k5L6", "value": "sk_us-west-2_abcdABCDefgh_567890abcdef", "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "tags": {} } }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

範例 2:若要建立啟用錄製功能的頻道,請使用其 ARN 指定的 RecordingConfiguration 資源

下列create-channel範例會建立新頻道和關聯的串流金鑰來開始串流,並設定頻道的錄製。

aws ivs create-channel \ --name test-channel-with-recording \ --insecure-ingest \ --recording-configuration-arn "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh"

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "test-channel-with-recording", "latencyMode": "LOW", "type": "STANDARD", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "BA1C2defGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": true, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "preset": "", "authorized": false, "tags": {}, "type": "STANDARD" }, "streamKey": { "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/abcdABCDefgh", "value": "sk_us-west-2_abcdABCDefgh_567890abcdef", "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "tags": {} } }

如需詳細資訊,請參閱 IVS 低延遲使用者指南中的記錄到 Amazon S3

範例 3:使用其 ARN 指定的播放限制原則來建立頻道

下列create-channel範例會建立新頻道和關聯的串流金鑰來開始串流,並設定頻道的播放限制原則。

aws ivs create-channel \ --name test-channel-with-playback-restriction-policy \ --insecure-ingest \ --playback-restriction-policy-arn "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ"

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "test-channel-with-playback-restriction-policy", "latencyMode": "LOW", "type": "STANDARD", "playbackRestrictionPolicyArn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ", "recordingConfigurationArn": "", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2edfGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": true, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "preset": "", "authorized": false, "tags": {}, "type": "STANDARD" }, "streamKey": { "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/abcdABCDefgh", "value": "sk_us-west-2_abcdABCDefgh_567890abcdef", "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "tags": {} } }

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器

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

下列程式碼範例會示範如何使用create-playback-restriction-policy

AWS CLI

建立播放限制原則

下列create-playback-restriction-policy範例會建立新的播放重新播放原則。

aws ivs create-playback-restriction-policy \ --name "test-playback-restriction-policy" \ --enable-strict-origin-enforcement \ --tags "key1=value1, key2=value2" \ --allowed-countries US MX \ --allowed-origins https://www.website1.com https://www.website2.com

輸出:

{ "playbackRestrictionPolicy": { "arn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ", "allowedCountries": [ "US", "MX" ], "allowedOrigins": [ "https://www.website1.com", "https://www.website2.com" ], "enableStrictOriginEnforcement": true, "name": "test-playback-restriction-policy", "tags": { "key1": "value1", "key2": "value2" } } }

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器

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

AWS CLI

建立 RecordingConfiguration 資源的步驟

下列create-recording-configuration範例會建立一個 RecordingConfiguration 資源以啟用 Amazon S3 的記錄功能。

aws ivs create-recording-configuration \ --name "test-recording-config" \ --recording-reconnect-window-seconds 60 \ --tags "key1=value1, key2=value2" \ --rendition-configuration renditionSelection="CUSTOM",renditions="HD" \ --thumbnail-configuration recordingMode="INTERVAL",targetIntervalSeconds=1,storage="LATEST",resolution="LOWEST_RESOLUTION" \ --destination-configuration s3={bucketName=demo-recording-bucket}

輸出:

{ "recordingConfiguration": { "arn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABcdef34ghIJ", "name": "test-recording-config", "destinationConfiguration": { "s3": { "bucketName": "demo-recording-bucket" } }, "state": "CREATING", "tags": { "key1": "value1", "key2": "value2" }, "thumbnailConfiguration": { "recordingMode": "INTERVAL", "targetIntervalSeconds": 1, "resolution": "LOWEST_RESOLUTION", "storage": [ "LATEST" ] }, "recordingReconnectWindowSeconds": 60, "renditionConfiguration": { "renditionSelection": "CUSTOM", "renditions": [ "HD" ] } } }

如需詳細資訊,請參閱 Amazon 互動式視訊服務使用者指南中的「錄製到 Amazon S3」。

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

AWS CLI

若要建立串流金鑰

下列create-stream-key範例會為指定的 ARN (Amazon 資源名稱) 建立串流金鑰。

aws ivs create-stream-key \ --channel-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh

輸出:

{ "streamKey": { "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/abcdABCDefgh", "value": "sk_us-west-2_abcdABCDefgh_567890abcdef", "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "tags": {} } }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

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

AWS CLI

若要刪除頻道及其相關聯的串流金鑰

下列delete-channel範例會刪除具有指定 ARN (Amazon 資源名稱) 的通道。

aws ivs delete-channel \ --arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh

此命令不會產生輸出。

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

下列程式碼範例會示範如何使用delete-playback-key-pair

AWS CLI

刪除指定的播放 key pair

下列delete-playback-key-pair範例會傳回指定 key pair 的指紋。

aws ivs delete-playback-key-pair \ --arn arn:aws:ivs:us-west-2:123456789012:playback-key/abcd1234efgh

此命令不會產生輸出。

如需詳細資訊,請參閱《Amazon 互動式影片服務使用者指南》中的設定私有頻道

下列程式碼範例會示範如何使用delete-playback-restriction-policy

AWS CLI

刪除播放限制原則

下列delete-playback-restriction-policy範例會刪除具有指定政策 ARN (Amazon 資源名稱) 的播放重新播放政策。

aws ivs delete-playback-restriction-policy \ --arn "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ"

此命令不會產生輸出。

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器

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

AWS CLI

若要刪除其 ARN 所指定的 RecordingConfiguration 資源

下列delete-recording-configuration範例會刪除具有指定 ARN 的 RecordingConfiguration 資源。

aws ivs delete-recording-configuration \ --arn "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABcdef34ghIJ"

此命令不會產生輸出。

如需詳細資訊,請參閱 Amazon 互動式視訊服務使用者指南中的「錄製到 Amazon S3」。

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

AWS CLI

若要刪除串流金鑰

下列delete-stream-key範例會刪除指定 ARN (Amazon 資源名稱) 的串流金鑰,因此無法再用於串流。

aws ivs delete-stream-key \ --arn arn:aws:ivs:us-west-2:123456789012:stream-key/g1H2I3j4k5L6

此命令不會產生輸出。

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

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

AWS CLI

取得頻道的組態資訊

下列get-channel範例會取得指定通道 ARN (Amazon 資源名稱) 的通道組態。

aws ivs get-channel \ --arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "channel-1", "latencyMode": "LOW", "type": "STANDARD", "playbackRestrictionPolicyArn": "", "preset": "", "recordingConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2defGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": false, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "tags": {} } }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

下列程式碼範例會示範如何使用get-playback-key-pair

AWS CLI

取得指定的播放 key pair

下列get-playback-key-pair範例會傳回指定 key pair 的指紋。

aws ivs get-playback-key-pair \ --arn arn:aws:ivs:us-west-2:123456789012:playback-key/abcd1234efgh

輸出:

{ "keyPair": { "arn": "arn:aws:ivs:us-west-2:123456789012:playback-key/abcd1234efgh", "name": "my-playback-key", "fingerprint": "0a:1b:2c:ab:cd:ef:34:56:70:b1:b2:71:01:2a:a3:72", "tags": {} } }

如需詳細資訊,請參閱《Amazon 互動式影片服務使用者指南》中的設定私有頻道

下列程式碼範例會示範如何使用get-playback-restriction-policy

AWS CLI

取得播放限制原則的組態資訊

下列get-playback-restriction-policy範例會取得具有指定政策 ARN (Amazon 資源名稱) 的播放限制政策組態。

aws ivs get-playback-restriction-policy \ --arn "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ"

輸出:

{ "playbackRestrictionPolicy": { "arn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ", "allowedCountries": [ "US", "MX" ], "allowedOrigins": [ "https://www.website1.com", "https://www.website2.com" ], "enableStrictOriginEnforcement": true, "name": "test-playback-restriction-policy", "tags": { "key1": "value1", "key2": "value2" } } }

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器

下列程式碼範例會示範如何使用get-recording-configuration

AWS CLI

若要取得有關資 RecordingConfiguration 源的資訊

下列get-recording-configuration範例會取得指定 ARN 之 RecordingConfiguration 資源的相關資訊。

aws ivs get-recording-configuration \ --arn "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABcdef34ghIJ"

輸出:

{ "recordingConfiguration": { "arn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABcdef34ghIJ", "destinationConfiguration": { "s3": { "bucketName": "demo-recording-bucket" } }, "name": "test-recording-config", "recordingReconnectWindowSeconds": 60, "state": "ACTIVE", "tags": { "key1" : "value1", "key2" : "value2" }, "thumbnailConfiguration": { "recordingMode": "INTERVAL", "targetIntervalSeconds": 1, "resolution": "LOWEST_RESOLUTION", "storage": [ "LATEST" ] }, "renditionConfiguration": { "renditionSelection": "CUSTOM", "renditions": [ "HD" ] } } }

如需詳細資訊,請參閱 Amazon 互動式視訊服務使用者指南中的「錄製到 Amazon S3」。

下列程式碼範例會示範如何使用get-stream-key

AWS CLI

取得串流的相關資訊

下列get-stream-key範例會取得指定串流金鑰的相關資訊。

aws ivs get-stream-key \ --arn arn:aws:ivs:us-west-2:123456789012:stream-key/skSKABCDefgh --region=us-west-2

輸出:

{ "streamKey": { "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/skSKABCDefgh", "value": "sk_us-west-2_abcdABCDefgh_567890abcdef", "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "tags": {} } }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

下列程式碼範例會示範如何使用get-stream-session

AWS CLI

若要取得指定串流的中繼資料

下列get-stream-session範例會取得指定通道 ARN (Amazon 資源名稱) 和指定串流的中繼資料組態;如果未提供 streamId,則會選取通道的最新串流。

aws ivs get-stream-session \ --channel-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh \ --stream-id "mystream"

輸出:

{ "streamSession": { "streamId": "mystream1", "startTime": "2023-06-26T19:09:28+00:00", "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "mychannel", "latencyMode": "LOW", "type": "STANDARD", "recordingConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABcdef34ghIJ", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2defGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "playbackUrl": "url-string", "authorized": false, "insecureIngest": false, "preset": "" }, "ingestConfiguration": { "video": { "avcProfile": "Baseline", "avcLevel": "4.2", "codec": "avc1.42C02A", "encoder": "Lavf58.45.100", "targetBitrate": 8789062, "targetFramerate": 60, "videoHeight": 1080, "videoWidth": 1920 }, "audio": { "codec": "mp4a.40.2", "targetBitrate": 46875, "sampleRate": 8000, "channels": 2 } }, "recordingConfiguration": { "arn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABcdef34ghIJ", "name": "test-recording-config", "destinationConfiguration": { "s3": { "bucketName": "demo-recording-bucket" } }, "state": "ACTIVE", "tags": { "key1": "value1", "key2": "value2" }, "thumbnailConfiguration": { "recordingMode": "INTERVAL", "targetIntervalSeconds": 1, "resolution": "LOWEST_RESOLUTION", "storage": [ "LATEST" ] }, "recordingReconnectWindowSeconds": 60, "renditionConfiguration": { "renditionSelection": "CUSTOM", "renditions": [ "HD" ] } }, "truncatedEvents": [ { "name": "Recording Start", "type": "IVS Recording State Change", "eventTime": "2023-06-26T19:09:35+00:00" }, { "name": "Stream Start", "type": "IVS Stream State Change", "eventTime": "2023-06-26T19:09:34+00:00" }, { "name": "Session Created", "type": "IVS Stream State Change", "eventTime": "2023-06-26T19:09:28+00:00" } ] } }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

下列程式碼範例會示範如何使用get-stream

AWS CLI

取得串流的相關資訊

下列get-stream範例會取得指定通道之串流的相關資訊。

aws ivs get-stream \ --channel-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh

輸出:

{ "stream": { "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "startTime": "2020-05-05T21:55:38Z", "state": "LIVE", "health": "HEALTHY", "streamId": "st-ABCDEfghij01234KLMN5678", "viewerCount": 1 } }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

下列程式碼範例會示範如何使用import-playback-key-pair

AWS CLI

若要匯入新 key pair 的公開部分

下列import-playback-key-pair範例會匯入指定的公用金鑰 (以 PEM 格式指定為字串),並傳回新 key pair 的 arn 和指紋。

aws ivs import-playback-key-pair \ --name "my-playback-key" \ --public-key-material "G1lbnQxOTA3BgNVBAMMMFdoeSBhcmUgeW91IGRl..."

輸出:

{ "keyPair": { "arn": "arn:aws:ivs:us-west-2:123456789012:playback-key/abcd1234efgh", "name": "my-playback-key", "fingerprint": "0a:1b:2c:ab:cd:ef:34:56:70:b1:b2:71:01:2a:a3:72", "tags": {} } }

如需詳細資訊,請參閱《Amazon 互動式影片服務使用者指南》中的設定私有頻道

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

AWS CLI

範例 1:取得所有頻道的摘要資訊

下列list-channels範例會列出您 AWS 帳戶的所有管道。

aws ivs list-channels

輸出:

{ "channels": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "channel-1", "latencyMode": "LOW", "authorized": false, "insecureIngest": false, "preset": "", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh", "tags": {}, "type": "STANDARD" }, { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/efghEFGHijkl", "name": "channel-2", "latencyMode": "LOW", "authorized": false, "preset": "", "playbackRestrictionPolicyArn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ", "recordingConfigurationArn": "", "tags": {}, "type": "STANDARD" } ] }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

示例 2:要獲取有關所有通道的摘要信息,由指定的 RecordingConfiguration ARN 過濾

下列list-channels範例會列出您 AWS 帳戶中與指定 RecordingConfiguration ARN 相關聯的所有通道。

aws ivs list-channels \ --filter-by-recording-configuration-arn "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh"

輸出:

{ "channels": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "channel-1", "latencyMode": "LOW", "authorized": false, "insecureIngest": false, "preset": "", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh", "tags": {}, "type": "STANDARD" } ] }

如需詳細資訊,請參閱 IVS 低延遲使用者指南中的記錄到 Amazon S3

示例 3:要獲取有關所有通道的摘要信息,由指定的 PlaybackRestrictionPolicy ARN 過濾

下列list-channels範例會列出您 AWS 帳戶中與指定 PlaybackRestrictionPolicy ARN 相關聯的所有通道。

aws ivs list-channels \ --filter-by-playback-restriction-policy-arn "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ"

輸出:

{ "channels": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/efghEFGHijkl", "name": "channel-2", "latencyMode": "LOW", "authorized": false, "preset": "", "playbackRestrictionPolicyArn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ", "recordingConfigurationArn": "", "tags": {}, "type": "STANDARD" } ] }

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器

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

下列程式碼範例會示範如何使用list-playback-key-pairs

AWS CLI

取得關於所有播放金鑰配對的摘要資訊

下列list-playback-key-pairs範例會傳回所有金鑰配對的相關資訊。

aws ivs list-playback-key-pairs

輸出:

{ "keyPairs": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:playback-key/abcd1234efgh", "name": "test-key-0", "tags": {} }, { "arn": "arn:aws:ivs:us-west-2:123456789012:playback-key/ijkl5678mnop", "name": "test-key-1", "tags": {} } ] }

如需詳細資訊,請參閱《Amazon 互動式影片服務使用者指南》中的設定私有頻道

下列程式碼範例會示範如何使用list-playback-restriction-policies

AWS CLI

取得有關所有播放限制原則的摘要資訊

下列list-playback-restriction-policies範例會列出您 AWS 帳戶的所有播放限制政策。

aws ivs list-playback-restriction-policies

輸出:

{ "playbackRestrictionPolicies": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ", "allowedCountries": [ "US", "MX" ], "allowedOrigins": [ "https://www.website1.com", "https://www.website2.com" ], "enableStrictOriginEnforcement": true, "name": "test-playback-restriction-policy", "tags": { "key1": "value1", "key2": "value2" } } ] }

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器

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

AWS CLI

列出在此帳號中建立的所有 RecordingConfiguration 資源

下列list-recording-configurations範例會取得帳戶中所有 RecordingConfiguration 資源的相關資訊。

aws ivs list-recording-configurations

輸出:

{ "recordingConfigurations": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABcdef34ghIJ", "name": "test-recording-config-1", "destinationConfiguration": { "s3": { "bucketName": "demo-recording-bucket-1" } }, "state": "ACTIVE", "tags": {} }, { "arn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/CD12abcdGHIJ", "name": "test-recording-config-2", "destinationConfiguration": { "s3": { "bucketName": "demo-recording-bucket-2" } }, "state": "ACTIVE", "tags": {} } ] }

如需詳細資訊,請參閱 Amazon 互動式視訊服務使用者指南中的「錄製到 Amazon S3」。

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

AWS CLI

若要取得串流金鑰清單

下列list-stream-keys範例會列出指定 ARN (Amazon 資源名稱) 的所有串流金鑰。

aws ivs list-stream-keys \ --channel-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh

輸出:

{ "streamKeys": [ { "arn": "arn:aws:ivs:us-west-2:123456789012:stream-key/abcdABCDefgh", "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "tags": {} } ] }

f 如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

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

AWS CLI

若要取得目前 AWS 區域中指定頻道的目前和之前串流的摘要

下列list-stream-sessions範例報告指定通道 ARN (Amazon 資源名稱) 的串流摘要資訊。

aws ivs list-stream-sessions \ --channel-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh \ --max-results 25 \ --next-token ""

輸出:

{ "nextToken": "set-2", "streamSessions": [ { "startTime": 1641578182, "endTime": 1641579982, "hasErrorEvent": false, "streamId": "mystream" } ... ] }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

AWS CLI

取得即時串流及其狀態的清單

下列list-streams範例會列出您 AWS 帳戶的所有即時串流。

aws ivs list-streams

輸出:

{ "streams": [ { "channelArn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "state": "LIVE", "health": "HEALTHY", "streamId": "st-ABCDEfghij01234KLMN5678", "viewerCount": 1 } ] }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

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

AWS CLI

若要列出 AWS 資源的所有標籤 (例如:頻道、串流金鑰)

下列list-tags-for-resource範例會列出指定資源 ARN (Amazon 資源名稱) 的所有標籤。

aws ivs list-tags-for-resource \ --resource-arn arn:aws:ivs:us-west-2:12345689012:channel/abcdABCDefgh

輸出:

{ "tags": { "key1": "value1", "key2": "value2" } }

如需詳細資訊,請參閱 Amazon 互動式影片服務 API 參考中的標記

下列程式碼範例會示範如何使用put-metadata

AWS CLI

若要將指定頻道的中繼資料插入作用中串流

下列put-metadata範例會將指定的中繼資料插入指定通道的串流中。

aws ivs put-metadata \ --channel-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh \ --metadata '{"my": "metadata"}'

此命令不會產生輸出。

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

下列程式碼範例會示範如何使用start-viewer-session-revocation

AWS CLI

撤銷指定多通道 ARN 和檢視器 ID 配對的檢視器工作階段

下列start-viewer-session-revocation範例會啟動撤銷與指定通道 ARN 和檢視器 ID 相關聯的檢視器工作階段的程序,直到並包含指定的工作階段版本號碼。如果未提供版本,則預設為 0。

aws ivs batch-start-viewer-session-revocation \ --channel-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh \ --viewer-id abcdefg \ --viewer-session-versions-less-than-or-equal-to 1234567890

此命令不會產生輸出。

如需詳細資訊,請參閱《Amazon 互動式影片服務使用者指南》中的設定私有頻道

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

AWS CLI

若要停止指定的串流

下列stop-stream範例會停止指定通道上的串流。

aws ivs stop-stream \ --channel-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh

此命令不會產生輸出。

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

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

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

AWS CLI

若要新增或更新 AWS 資源的標籤 (例如:通道、串流金鑰)

下列tag-resource範例會新增或更新指定資源 ARN (Amazon 資源名稱) 的標籤。

aws ivs tag-resource \ --resource-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh \ --tags "tagkey1=tagvalue1, tagkey2=tagvalue2"

此命令不會產生輸出。

如需詳細資訊,請參閱 Amazon 互動式影片服務 API 參考中的標記

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

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

AWS CLI

若要移除 AWS 資源的標籤 (例如:通道、串流金鑰)

下列untag-resource範例會移除指定資源 ARN (Amazon 資源名稱) 的指定標籤。

aws ivs untag-resource \ --resource-arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh \ --tag-keys "tagkey1, tagkey2"

此命令不會產生輸出。

如需詳細資訊,請參閱 Amazon 互動式影片服務 API 參考中的標記

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

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

AWS CLI

範例 1:若要更新頻道的組態資訊

下列update-channel範例會更新指定通道 ARN 的通道組態,以變更通道名稱。這不會影響此頻道的持續串流;您必須停止並重新啟動串流,變更才會生效。

aws ivs update-channel \ --arn arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh \ --name "channel-1" \ --insecure-ingest

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "channel-1", "latencyMode": "LOW", "type": "STANDARD", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2defGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": true, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "preset": "", "authorized": false, "tags": {} }

如需詳細資訊,請參閱「IVS 低延遲使用者指南」中的「建立通道」。

範例 2:更新頻道的設定以啟用錄製功能

下列update-channel範例會更新指定頻道 ARN 的頻道組態,以啟用錄製功能。這不會影響此頻道的持續串流;您必須停止並重新啟動串流,變更才會生效。

aws ivs update-channel \ --arn "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh" \ --no-insecure-ingest \ --recording-configuration-arn "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh"

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "test-channel-with-recording", "latencyMode": "LOW", "type": "STANDARD", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "arn:aws:ivs:us-west-2:123456789012:recording-configuration/ABCD12cdEFgh", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "BA1C2defGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": false, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "preset": "", "authorized": false, "tags": {} } }

如需詳細資訊,請參閱 IVS 低延遲使用者指南中的記錄到 Amazon S3

範例 3:更新頻道的設定以停用錄製

下列update-channel範例會更新指定頻道 ARN 的頻道組態,以停用錄製功能。這不會影響此頻道的持續串流;您必須停止並重新啟動串流,變更才會生效。

aws ivs update-channel \ --arn "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh" \ --recording-configuration-arn ""

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "test-channel-with-recording", "latencyMode": "LOW", "type": "STANDARD", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2edfGHijkLMNo3PqQRstUvwxyzaBCDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": false, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "preset": "", "authorized": false, "tags": {} } }

如需詳細資訊,請參閱 IVS 低延遲使用者指南中的記錄到 Amazon S3

範例 4:更新頻道的設定以啟用播放限制

下列update-channel範例會更新指定頻道 ARN 的頻道組態,以套用播放限制原則。這不會影響此頻道的持續串流;您必須停止並重新啟動串流,變更才會生效。

aws ivs update-channel \ --arn "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh" \ --no-insecure-ingest \ --playback-restriction-policy-arn "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ"

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "test-channel-with-playback-restriction-policy", "latencyMode": "LOW", "type": "STANDARD", "playbackRestrictionPolicyArn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ", "recordingConfigurationArn": "", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2defGHijkLMNo3PqQRstUvwxyzaCBDEfghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": false, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "preset": "", "authorized": false, "tags": {} } }

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器

範例 5:更新頻道的設定以停用播放限制

下列update-channel範例會更新指定頻道 ARN 的頻道組態,以停用播放限制。這不會影響此頻道的持續串流;您必須停止並重新啟動串流,變更才會生效。

aws ivs update-channel \ --arn "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh" \ --playback-restriction-policy-arn ""

輸出:

{ "channel": { "arn": "arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh", "name": "test-channel-with-playback-restriction-policy", "latencyMode": "LOW", "type": "STANDARD", "playbackRestrictionPolicyArn": "", "recordingConfigurationArn": "", "srt": { "endpoint": "a1b2c3d4e5f6.srt.live-video.net", "passphrase": "AB1C2defGHijkLMNo3PqQRstUvwxyzaBCDeFghh4ijklMN5opqrStuVWxyzAbCDEfghIJ" }, "ingestEndpoint": "a1b2c3d4e5f6.global-contribute.live-video.net", "insecureIngest": false, "playbackUrl": "https://a1b2c3d4e5f6.us-west-2.playback.live-video.net/api/video/v1/us-west-2.123456789012.channel.abcdEFGH.m3u8", "preset": "", "authorized": false, "tags": {} } }

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器

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

下列程式碼範例會示範如何使用update-playback-restriction-policy

AWS CLI

更新播放限制原則

下列update-playback-restriction-policy範例會使用指定的原則 ARN 來更新播放限制原則,以停用嚴格的來源強制執行。這不會影響關聯頻道的持續串流;您必須停止並重新啟動串流,變更才會生效。

aws ivs update-playback-restriction-policy \ --arn "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ" \ --no-enable-strict-origin-enforcement

輸出:

{ "playbackRestrictionPolicy": { "arn": "arn:aws:ivs:us-west-2:123456789012:playback-restriction-policy/ABcdef34ghIJ", "allowedCountries": [ "US", "MX" ], "allowedOrigins": [ "https://www.website1.com", "https://www.website2.com" ], "enableStrictOriginEnforcement": false, "name": "test-playback-restriction-policy", "tags": { "key1": "value1", "key2": "value2" } } }

如需詳細資訊,請參閱《IVS 低延遲使用者指南》中的不需要的內容和檢視器