Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions projects/S3_File_Upload/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

## Simple Python script for AWS S3 file upload.

### Prerequisites
boto3 (pip install boto3) <br />

### How to run the script
- Specify both ACCESS_KEY and SECRET_KEY. You can get them both on your AWS account in "My Security Credentials" section. <br />
- Specify the local file name, bucket name and the name that you want the file to have inside s3 bucket using LOCAL_FILE, BUCKET_NAME and S3_FILE_NAME variables. <br />
- Run "python main.py" <br />

### Author Name
Miguel Wychovaniec - https://github.com/miguelwy
26 changes: 26 additions & 0 deletions projects/S3_File_Upload/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import boto3
from botocore.exceptions import NoCredentialsError

ACCESS_KEY = 'XXXXXXXXXXXXXXXXX'
SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
LOCAL_FILE = 'local_file_name'
BUCKET_NAME = 'bucket_name'
S3_FILE_NAME = 'file_name_on_s3'

def upload_to_s3(local_file, bucket, s3_file):
## This function is responsible for uploading the file into the S3 bucket using the specified credentials.
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


result = upload_to_s3(LOCAL_FILE, BUCKET_NAME, S3_FILE_NAME)
2 changes: 2 additions & 0 deletions projects/S3_File_Upload/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3==1.20.4
botocore==1.23.4