Skip to content

Instantly share code, notes, and snippets.

@arundhaj
Created January 29, 2022 11:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arundhaj/134775031ef916301c9aeff4c089466c to your computer and use it in GitHub Desktop.
Save arundhaj/134775031ef916301c9aeff4c089466c to your computer and use it in GitHub Desktop.
AWS S3 Presigned URL for upload and download
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment