-
-
Save ftntming/4d55945c084b5d44d579a672a37db47e to your computer and use it in GitHub Desktop.
Bash script to Upload folder to S3
This file contains hidden or 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
# Set AWS credentials and S3 paramters | |
AWS_KEY="" | |
AWS_SECRET="" | |
S3_BUCKET="" | |
S3_BUCKET_PATH="/" | |
S3_ACL="x-amz-acl:private" | |
function s3Upload | |
{ | |
path=$1 | |
file=$2 | |
acl=${S3_ACL} | |
bucket=${S3_BUCKET} | |
bucket_path=${S3_BUCKET_PATH} | |
date=$(date +"%a, %d %b %Y %T %z") | |
content_type="application/octet-stream" | |
sig_string="PUT\n\n$content_type\n$date\n$acl\n/$bucket$bucket_path$file" | |
signature=$(echo -en "${sig_string}" | openssl sha1 -hmac "${AWS_SECRET}" -binary | base64) | |
curl -X PUT -T "$path/$file" \ | |
-H "Host: $bucket.s3.amazonaws.com" \ | |
-H "Date: $date" \ | |
-H "Content-Type: $content_type" \ | |
-H "$acl" \ | |
-H "Authorization: AWS ${AWS_KEY}:$signature" \ | |
"https://$bucket.s3.amazonaws.com$bucket_path$file" | |
} | |
# set the path based on the first argument | |
path=$1 | |
# loop through the path and upload the files | |
for file in "$path"/*; do | |
s3Upload "$path" "${file##*/}" "/" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment