AWS S3 Signed Upload URL Basics

While I found a number of examples for generating signed upload S3 URLs, there didn’t seem to be examples with the basics.

After substituting the name for your bucket, file name and expiry desired, run below code to generate the URL:

import boto3

if __name__ == "__main__":
    s3_client = boto3.client('s3')
    response = s3_client.generate_presigned_url(
        ClientMethod='put_object',
        Params={"Bucket": "mybucket", "Key": "file.pdf"},
        ExpiresIn=48*60*60,
        HttpMethod="PUT")
    print(response)

To upload from command line run below (substituting URL from previous section):

curl "https://mybucket.s3.amazonaws.com/file.pdf?AWSAccessKeyId=AKIAWR6H3WAK6NZTVBJP&Signature=CkFT8z3KK8zznNSZ6sOZryFHQTM%3D&Expires=1584826340" --upload-file file.pdf
comments powered by Disqus

Related