Amazon Kinesis Video GetMedia/PutMedia

Question:

I used python 3.6 and I want to post video stream to aws kinesis with API.
I used python aws client to create stream and GetDataEndPoint but when I want to post my data with my custom request (PutMedia doesn’t include in python client actually), I get an error Unable to determine service/operation name to be authorized.

I’ve follow the api doc of aws kinesis video media PutMedia and GetMedia.

So I start by getting endpoint with GetDataEndPoint with client method:

response = client.get_data_endpoint(  # aws client method
    StreamName=STREAM_NAME,
    APIName='PUT_MEDIA'
)
end_point = response['DataEndpoint'] # https://s-EXAMPLE.kinesisvideo.eu-west-1.amazonaws.com

and I post my data at this url:

headers = {
    "x-amzn-stream-arn": STREAM_ARN,
    "x-amzn-fragment-timecode-type": "ABSOLUTE",
    "x-amzn-producer-start-timestamp": start_tmstp
}
# Sign header...
response = requests.post(end_point, data=data, headers=headers)  # 403 - Unable to determine service/operation name to be authorized

So I don’t understand why I get this error… I’ve found this troubleshooting on aws doc. But they say we must specify ApiName parameter. What I do…

This error might occur if the endpoint is not properly specified. When you are getting the endpoint, be sure to include the following parameter in the GetDataEndpoint call, depending on the API to be called:

I’m also wondering if the GetMedia method is actually implemented in client as they say here because when I debug this method, client don’t call GetDataEndPoint and so make request at https://kinesisvideo.region.amazonaws.com insteed of https://ID_EXAMPLE.kinesisvideo.region.amazonaws.com. So method get error Unable to determine service/operation name to be authorized as explained in troubleshooting

Asked By: hgcahez

||

Answers:

The error you’re getting is because you’re probably providing the endpoint without the “action” that in your case would be putMedia.

Try to append /putMedia to your endpoint and don’t forget to specify the "content-type": "application/json" header.

Btw you have also to generate the v4 signatures for your request. You can use a lib or follow this python guide to do it.

Answered By: Rocco Musolino

Following @minghua answer code, clear all problems by converting source video to .mkv . Once I did this, flowed perfectly.

Answered By: Guima