Search code examples
amazon-s3boto3wildcardpre-signed-url

How to use wildcards for key/object to generate AWS S3 pre-signed url


My requirement is to upload multiple webm files(which are captured using webrtc) to S3 using one time generated pre-signed url.

I have tried below code to generate pre-signed url and using postman to upload files

def create_presigned_url(method_name,s3object,expiration=36000):
    
    try:
        response = s3_client.generate_presigned_post(S3Bucket,
                                                     Key = "",
                                                     Fields=None,
                                                     Conditions = [
                                                                    ["content-length-range",  100, 1000000000],
                                                                    ["starts-with", "$key", "/path-to-file/]
                                                        ],
                                                     ExpiresIn=expiration)
       
    except Exception as e:
        logging.error(e)
        return None
    return response

I am getting the below error when I tried from postman:

enter image description here


Solution

  • Wildcards are not supported in presigned URLs.

    I have not been able to find any documentation that clearly states this, however I had to achieve the same today and my findings show that it is not possible.

    I created a presigned URL with the key test/*.
    I was only able to retrieve the content of a file in S3 that was named test/*, but not any other files with the test/ prefix. For each of the other files the request failed because "The request signature we calculated does not match the signature you provided. Check your key and signing method.".

    This error specifically states that the request does not match the signature, which is different than when I made a sign url to an object that does not exist and the request fails because the key could not be found.