Boto3 kinesis视频流:调用GetMedia操作时出错

时间:2018-04-10 06:16:44

标签: python-3.x amazon-web-services boto3 amazon-kinesis

在boto3文档下:https://boto3.readthedocs.io/en/latest/reference/services/kinesis-video-media.html#KinesisVideoMedia.Client.get_media

它说我需要首先运行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

然后返回:

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方法?

1 个答案:

答案 0 :(得分:6)

首先,使用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'}}}