0
votes

I am trying to upload a video to an S3 bucket using the API interface, I followed the presigned URL procedure, here is my lambda function that returns the presigned URL (it returns the presigned url correctly - seemingly):

import json
import base64
import boto3
import uuid
BUCKET_NAME = 'redacted-bucket-instance'

def lambda_handler(event, context):
    actionId = uuid.uuid4()
    file_path = "video_uploads/" + str(actionId) + ".mp4"
    s3 = boto3.client('s3')
    s3Params = {
        "Bucket": BUCKET_NAME,
        "Key": file_path,
        "ContentType": 'video/mp4',
        "ACL": 'public-read'
    }
    try:
        s3_response = s3.generate_presigned_url('put_object', Params=s3Params, ExpiresIn=3600, HttpMethod="PUT")
    except Exception as e:
        raise IOError(e)
    return {
        'statusCode': 200,
        'body': {
            'file_path': file_path,
            'url': s3_response
        }
    }

when I try to upload an mp4 video with curl like this for ex: curl -X PUT -F 'data=@ch01_00000100055009702.mp4' https://redacted-bucket-instance.s3.amazonaws.com//video_uploads/a845a97f-a218-4815-a836-376e498a4334.mp4?AWSAccessKeyId=ASIAWZPXMJR5V7GEHUJJ&Signature=zDsdfsdfqsdfD&content-type=video%2Fmp4&x-amz-acl=public-read&etc

or

curl -X PUT --data-binary '@ch01_00000100055009702.mp4' https://redacted-bucket-instance.s3.amazonaws.com//video_uploads/a845a97f-a218-4815-a836-376e498a4334.mp4?AWSAccessKeyId=ASIAWZPXMJR5V7GEHUJJ&Signature=zDsdfsdfqsdfD&content-type=video%2Fmp4&x-amz-acl=public-read&etc

in both cases, the terminal closes...whatcould I be doing wrong here?

(both url are not the ones received of course but just there for demonstration)

Edit

Adding quotes for the url prevented the terminal from closing and gave a reponse.(I'm guessing some characters needed to be escaped)

Now I'm getting this error:

<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>ASIAWZPXMJR54PMEJVPQ</AWSAccessKeyId>

Should I add headers in the request for it to work?

(I renewed the presigned url to make sure it's valid during teseting)

1
What do you mean by "the terminal closes"? Don't you see any output from the curl command? Have you tried running curl with the -v option? It should show more information about the request and response. - Hernán Alarcón
@HernánAlarcón adding quotes to the URL made it work. I added an edit to the question with the error I got as a result - John Doe
Why does the error message shows a different AWS Access Key Id from the one you are using in your curl commands? - Hernán Alarcón
@HernánAlarcón I think it's because I changed the lambda function a bit(trying to fix it googling people having the same issue: changed the Key to a constant string and removed ACL - John Doe
I was reading this stackoverflow.com/questions/30518899/… and thought one of them might cause the issue - John Doe

1 Answers

0
votes

The solution for me was to first add quotes for the url (as mentioned in the edit) and also add a Content-Type header

-H "Content-Type:video/mp4"
  • no space between ':' and video or it will lead to an error as well (at least in my case)