Last active
May 28, 2020 12:36
-
-
Save siakon89/51e4dd83724c9d2b0e1e0df6482a4009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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