Boto3 运动视频流:调用 GetMedia 操作时出错
Boto3 kinesis video stream: Error when calling the GetMedia operation
它说我需要先 运行 GetDataEndpoint
API 才能在 运行 GetMedia
之前获得一个端点,但它没有说如何输入端点?
所以我尝试了 运行:
import boto3
kinesis_media = boto3.client('kinesis-video-media' region_name='region')
stream = kinesis_media.get_media(StreamARN='my-arn',
StartSelector={'StartSelectorType': 'EARLIEST'}) # this is not the endpoint
然后 returns:
ClientError: An error occurred (403) when calling the GetMedia operation: <AccessDeniedException>
<Message>Unable to determine service/operation name to be authorized</Message>
</AccessDeniedException>
我猜是因为未指定端点,但类型 kinesis-video-media
的客户端没有获取端点所需的 get_data_endpoint
方法 url?
首先,使用kinesisvideo
客户端获取端点:
import boto3
kinesis_client = boto3.client('kinesisvideo',region_name='us-west-2')
response = kinesis_client.get_data_endpoint(StreamARN='...ARN...',APIName='GET_MEDIA')
response
变量包含:
{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '...', 'HTTPHeaders': {'x-amzn-requestid': '...', 'date': 'Tue, 10 Apr 2018 08:22:59 GMT', 'content-length': '74', 'content-type': 'application/json'}}, u'DataEndpoint': u'https://s-4010cf70.kinesisvideo.us-west-2.amazonaws.com'}
然后,使用给定端点调用 kinesis-video-media
客户端:
video_client = boto3.client('kinesis-video-media',endpoint_url='https://s-4010cf70.kinesisvideo.us-west-2.amazonaws.com',region_name='us-west-2')
stream = video_client.get_media(StreamARN='arn:aws:kinesisvideo:us-west-2:...',StartSelector={'StartSelectorType': 'NOW'})
stream
变量包含:
{u'ContentType': 'video/webm', u'Payload': <botocore.response.StreamingBody object at 0x7f1fab294850>, 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '...', 'HTTPHeaders': {'x-amzn-requestid': '...', 'transfer-encoding': 'chunked', 'content-type': 'video/webm', 'date': 'Tue, 10 Apr 2018 08:27:19 GMT'}}}
它说我需要先 运行 GetDataEndpoint
API 才能在 运行 GetMedia
之前获得一个端点,但它没有说如何输入端点?
所以我尝试了 运行:
import boto3
kinesis_media = boto3.client('kinesis-video-media' region_name='region')
stream = kinesis_media.get_media(StreamARN='my-arn',
StartSelector={'StartSelectorType': 'EARLIEST'}) # this is not the endpoint
然后 returns:
ClientError: An error occurred (403) when calling the GetMedia operation: <AccessDeniedException>
<Message>Unable to determine service/operation name to be authorized</Message>
</AccessDeniedException>
我猜是因为未指定端点,但类型 kinesis-video-media
的客户端没有获取端点所需的 get_data_endpoint
方法 url?
首先,使用kinesisvideo
客户端获取端点:
import boto3
kinesis_client = boto3.client('kinesisvideo',region_name='us-west-2')
response = kinesis_client.get_data_endpoint(StreamARN='...ARN...',APIName='GET_MEDIA')
response
变量包含:
{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '...', 'HTTPHeaders': {'x-amzn-requestid': '...', 'date': 'Tue, 10 Apr 2018 08:22:59 GMT', 'content-length': '74', 'content-type': 'application/json'}}, u'DataEndpoint': u'https://s-4010cf70.kinesisvideo.us-west-2.amazonaws.com'}
然后,使用给定端点调用 kinesis-video-media
客户端:
video_client = boto3.client('kinesis-video-media',endpoint_url='https://s-4010cf70.kinesisvideo.us-west-2.amazonaws.com',region_name='us-west-2')
stream = video_client.get_media(StreamARN='arn:aws:kinesisvideo:us-west-2:...',StartSelector={'StartSelectorType': 'NOW'})
stream
变量包含:
{u'ContentType': 'video/webm', u'Payload': <botocore.response.StreamingBody object at 0x7f1fab294850>, 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '...', 'HTTPHeaders': {'x-amzn-requestid': '...', 'transfer-encoding': 'chunked', 'content-type': 'video/webm', 'date': 'Tue, 10 Apr 2018 08:27:19 GMT'}}}