We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f4bb6a2 commit 4bb9903Copy full SHA for 4bb9903
1 file changed
projects/S3_File_Upload/main.py
@@ -0,0 +1,22 @@
1
+import boto3
2
+from botocore.exceptions import NoCredentialsError
3
+
4
+ACCESS_KEY = 'XXXXXXXXXXXXXXXXX'
5
+SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
6
7
+def upload_to_s3(local_file, bucket, s3_file):
8
+ s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
9
+ aws_secret_access_key=SECRET_KEY)
10
+ try:
11
+ s3.upload_file(local_file, bucket, s3_file)
12
+ print("Upload Successful")
13
+ return True
14
+ except FileNotFoundError:
15
+ print("The file was not found")
16
+ return False
17
+ except NoCredentialsError:
18
+ print("Credentials not available")
19
20
21
22
+result = upload_to_s3('local_file_name', 'bucket_name', 'file_name_on_s3')
0 commit comments