Skip to content

Instantly share code, notes, and snippets.

@siakon89
Last active May 28, 2020 12:36
Show Gist options
  • Save siakon89/51e4dd83724c9d2b0e1e0df6482a4009 to your computer and use it in GitHub Desktop.
Save siakon89/51e4dd83724c9d2b0e1e0df6482a4009 to your computer and use it in GitHub Desktop.
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