Skip to content

Instantly share code, notes, and snippets.

@hansheng0512
Last active September 9, 2021 06:33
Show Gist options
  • Select an option

  • Save hansheng0512/15200ce7cf60a777550752027baac59d to your computer and use it in GitHub Desktop.

Select an option

Save hansheng0512/15200ce7cf60a777550752027baac59d to your computer and use it in GitHub Desktop.
AWS S3
import boto3
from botocore.exceptions import NoCredentialsError
ACCESS_KEY = "xxxxxxxxxxxx"
SECRET_KEY = "xxxxxxxxxxxxxxxxxxxx"
def upload_to_aws(local_file, bucket, s3_file):
s3 = boto3.client("s3", aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
try:
s3.upload_file(local_file, bucket, s3_file)
print("Upload Successful")
return True
except FileNotFoundError:
print("The file was not found")
return False
except NoCredentialsError:
print("Credentials not available")
return False
uploaded = upload_to_aws("<File Path>", "<Bucket Name>", "<Bucket Filename>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment