Skip to content

Instantly share code, notes, and snippets.

@ambujraj
Created September 23, 2021 14:31
Show Gist options
  • Save ambujraj/ffce10958dedd4d7c2fafaf93dea61f8 to your computer and use it in GitHub Desktop.
Save ambujraj/ffce10958dedd4d7c2fafaf93dea61f8 to your computer and use it in GitHub Desktop.
Python script to upload file to S3.
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