Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created October 21, 2016 06:50
Show Gist options
  • Save harshavardhana/f6814f3196bc307faa24e42394cc6df0 to your computer and use it in GitHub Desktop.
Save harshavardhana/f6814f3196bc307faa24e42394cc6df0 to your computer and use it in GitHub Desktop.
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="YOUR-ACCESSKEY"
S3SECRET="YOUR-SECRETKEY"
function putS3
{
path=$1
file=$2
aws_path=$3
bucket='my-bucket'
date=$(date +"%a, %d %b %Y %T %z")
content_type='application/octet-stream'
string="PUT\n\n$content_type\n$date\n\n/$bucket$aws_path$file"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
curl -X PUT -T "$path/$file" \
-H "Host: play.minio.io:9000" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "Authorization: AWS ${S3KEY}:$signature" \
"https://play.minio.io:9000/$bucket/$aws_path$file"
}
for file in "$path"/*; do
putS3 "$path" "${file##*/}" "/path/on/s3/to/files/"
done
@marinheiromc
Copy link

Hey nice script man, do you think its worth to mention if the user is using temporary keys it will need to use the header "x-amz-security-token"? we ( aws ) are getting a few users that are having problems with that, anyway just a suggestion :) cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment