- boto3 SDK is installed on your machine
- https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html
- (OPTIONAL) Create a new S3 Bucket
- Open a new text file and copy this code and save it as a .py file
import boto3
s3 = boto3.client('s3')
"""
If you don't have CLI and therefore AWS Credentials setup , then un-comment the lines below and remove the line above. Add your AWS credentials.
s3 = boto3.client(
's3',
aws_access_key_id='AKIAIO5FODNN7EXAMPLE',
aws_secret_access_key='ABCDEF+c2L7yXeGvUyrPgYsDnWRRC1AYEXAMPLE'
config=Config(signature_version='s3v4'
)
"""
bucket = raw_input("Enter your Bucket Name: ")
key= raw_input("Enter your desired filename/key for this upload: ")
print (" Generating pre-signed url...")
print(s3.generate_presigned_url('put_object', Params={'Bucket':bucket,'Key':key}, ExpiresIn=3600, HttpMethod='PUT'))
- On your command line/terminal navigate to the directory/folder where you saved the .py file
- Execute the script and enter your bucket name and desired filename/key
python presign.py
- You will receive a pre-signed url as seen above. Copy that to the clipboard
- On your command Line use curl to upload any file to S3 using Pre-signed URL
curl --request PUT --upload-file text.txt http://your-pre-signed-url.com
- Check your S3 bucket and your upload should be successful. Congrats!
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3.html#generating-presigned-posts