Skip to content

Instantly share code, notes, and snippets.

@siakon89 siakon89/upload_images.py

Last active May 28, 2020
Embed
What would you like to do?
import boto3
from boto3.s3.transfer import TransferConfig
BUCKET = "<your bucket from SAM template>"
REGION = "<your region>"
PROFILE = "<your profile>"
def upload_to_s3(file_name, key, bucket=BUCKET, region=REGION):
# Multipart upload config
config = TransferConfig(
multipart_threshold=1024 * 25,
max_concurrency=10,
multipart_chunksize=1024 * 25,
use_threads=True,
)
# I have separate profiles in aws so I have to define one here
# in order to authenticate myself to my account
# If you do not have multiple profiles, just remove the argument
session = boto3.Session(profile_name=PROFILE)
s3 = session.client("s3", region_name=region)
# Upload file to S3
s3.upload_file(file_name, bucket, key, Config=config)
upload_to_s3("local file", "key on s3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.