Created
September 23, 2021 14:31
-
-
Save ambujraj/ffce10958dedd4d7c2fafaf93dea61f8 to your computer and use it in GitHub Desktop.
Python script to upload file to S3.
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 | |
import sys | |
import os | |
def upload(file_name, bucket_name, key=None): | |
if(key is None): | |
key = os.path.basename(file_name) | |
client = boto3.client('s3') | |
try: | |
client.upload_file(file_name, bucket_name, key) | |
print("Upload Success!") | |
except: | |
print("Failed to upload") | |
arguments = sys.argv | |
if(len(arguments) in {3,4}): | |
file_name = arguments[1] | |
bucket_name = arguments[2] | |
key = arguments[3] if len(arguments)==4 else None | |
upload(file_name, bucket_name, key) | |
else: | |
print("Not enough parameters") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment