POST file to AWS Mediastore with Python 3 without SDK, without CLI
did you try to change the method from method = 'PUT'
to method = 'POST'
? I think that will help you since the method used in the DOCs is POST
use this code for SHA Key Signing:
def sign(key, msg):
return hmac.new(key, msg.encode("utf-8"), hashlib.sha256).digest()
def getSignatureKey(key, dateStamp, regionName, serviceName):
kDate = sign(("AWS4" + key).encode("utf-8"), dateStamp)
kRegion = sign(kDate, regionName)
kService = sign(kRegion, serviceName)
kSigning = sign(kService, "aws4_request")
return kSigning
Source AWS
and Troubleshooting
Regular Upload Request : Source: AWS-PDF
POST premium/canada/mlaw.avi
Host: aaabbbcccdddee.files.mediastore-us-west-2.com
x-amz-Date: 20170323T120000Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20141123/us-
west-2/mediastore/aws4_request,SignedHeaders=host;x-amz-date;x-amz-mediastore-version,Signature=9257c16da6b25a715ce900a5b45b03da0447acf430195dcb540091b12966f2a2
Content-Length: 0
x-amz-mediastore-version: 2016-07-11
The following things were wrong in my script :
The canonical_uri
must be set to : /filename.mp4
The following headers are necessary : host,contentlength,x-amz-content-sha256,x-amz-date
The payload_hash
must be set to UNSIGNED-PAYLOAD
Here is the working curl request (with Ruby variables) :
`curl -v -X PUT -T #{target_file} \\
-H "Content-Lenght: #{file_size}" \\
-H "host: #{host}" \\
-H "X-Amz-Content-Sha256: #{payload_hash}" \\
-H "X-Amz-Date: #{timestamp}" \\
-H "Authorization: AWS4-HMAC-SHA256 Credential=#{access_key_id + '/' + credential_scope}, SignedHeaders=#{headers_lst}, Signature=#{signature}" \\
"https://qwerty123.data.mediastore.ap-northeast-1.amazonaws.com#{canonical_uri}?#{request_parameters}"`
@TonyJafar : thanks for your help