s3upload
With this simple program, you can upload multiple files at once to Amazon Web Services(AWS) S3 using one command. It uploads the files, makes them public, and then prints their URLs.
s3upload is written in Python3, and it uses Boto 3 to deal with AWS S3.
Prerequisites
This program requires Python3 with these libraries:
-
Boto 3: install with
pip install boto3
. -
requests: install with
pip install requests
.
AWS Credentials
For s3upload to be able to connect to your AWS account, you need to add your AWS credentials. It is a simple process.
-
Go to AWS IAM Console.
-
Create a new user or use an existing user.
-
Generate a new set of keys for the user.
-
Create a file named
credentials
in the directory~/.aws/
(Create~/.aws/
if it's not already there). -
Put the following in
credentials
file:
[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY
You're done!
Make file executable
After you download s3upload
file from this repository, make it executable using the command:
chmod +x s3upload
and then put it in /usr/local/bin
(or any path in your $PATH
variable) so you can call it directly from the command line.
Usage
s3upload LOCAL_DIRECTORY BUCKET_NAME [-d DEST_DIRECTORY] [-ext FILES_EXTENSIONS]
where:
-
LOCAL_DIRECTORY is the path to the local directory which contains the local files to be transferred.
-
BUCKET_NAME is the name of the destination S3 bucket.
-
DEST_DIRECTORY (optional) is the path inside the destination bucket that the files need to be transferred to. Note that it should not start with '/'. If it is not specified, files will be uploaded to the main bucket directory.
-
FILES_EXTENSION (optional) is the extensions of the files in LOCAL_DIRECTORY that need to be transfered. Extensions should be separated by ',' only. If FILES_EXTENSION is not specified, all files in the directory are uploaded (except files whose names start with '.').
This program uploads files only; folders are ignored.
Enclose all arguments with quotation marks, as shown in the example below.
Example
s3upload "/Users/abc/xyz/" "bucket_3" -d "2018/Nov/" -ext "png,csv"
This will upload all png and csv files in the local directory 'xyz' to the directory '2018/Nov/' inside bucket_3.
License
My work is licensed under MIT. Copyright (c) 2018 Ammar Alyousfi