Last active
September 9, 2021 06:33
-
-
Save hansheng0512/15200ce7cf60a777550752027baac59d to your computer and use it in GitHub Desktop.
AWS S3
This file contains hidden or 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 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