arundhaj

all that is technology

Creating AWS S3 Presigned URL for uploading and downloading files in Python using Boto3

 

In this video I'll show how create AWS S3 presigned URL for uploading and downloading files in Python using Boto3.

You can find the code snippet below

from pprint import pprint

import boto3

session = boto3.Session(profile_name='arundhaj')

s3_client = session.client('s3')

s3_bucket_name = 'codepossibility-presigned'
object_name = 'TestUploadFile.txt'


def create_bucket():
    response = s3_client.create_bucket(Bucket=s3_bucket_name)
    pprint(response)


def file_upload():
    response = s3_client.generate_presigned_post(
        s3_bucket_name,
        object_name,
        ExpiresIn=3600
    )
    pprint(response)


def file_download():
    response = s3_client.generate_presigned_url(
        'get_object',
        Params={
            'Bucket': s3_bucket_name,
            'Key': object_name
        },
        ExpiresIn=3600
    )

    pprint(response)


# create_bucket()
# file_upload()
file_download()

Hope this helps!

  Python

Comments