Skip to content

Instantly share code, notes, and snippets.

@Allwin12
Created May 23, 2020 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allwin12/e0be533ddefe96e1e20e963a0544b667 to your computer and use it in GitHub Desktop.
Save Allwin12/e0be533ddefe96e1e20e963a0544b667 to your computer and use it in GitHub Desktop.
from boto3 import Session
import string
import random
ACCESS_KEY = "your access key"
SECRET_KEY = "your_secret_key"
REGION_NAME = "your bucket's region name"
BUCKET_NAME = "your bucket name"
ses = Session(aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
region_name=REGION_NAME)
key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(10))
file = 'test.pdf'
content_type = 'application/pdf'
s3 = ses.resource('s3')
s3.Bucket(BUCKET_NAME).put_object(Key=key, Body=open(file, 'rb'), ACL='public-read', ContentType=content_type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment