Last active
December 10, 2018 04:56
-
-
Save johnbocook/95dd42114773ce672b2b06f779ef0d0c to your computer and use it in GitHub Desktop.
AWS S3 Upload
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
| S3KEY="my aws key" | |
| S3SECRET="my aws secret" | |
| function uploadS3 | |
| { | |
| path=$1 | |
| file=$2 | |
| aws_path=$3 | |
| bucket='aws-bucket-name' | |
| date=$(date +"%a, %d %b %Y %T %z") | |
| acl="x-amz-acl:public-read" | |
| content_type='application/x-compressed-tar' | |
| string="PUT\n\n$content_type\n$date\n$acl\n/$bucket$aws_path$file" | |
| signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -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 ${S3KEY}:$signature" \ | |
| "https://$bucket.s3.amazonaws.com$aws_path$file" | |
| } | |
| for file in "$path"/*; do | |
| putS3 "$path" "${file##*/}" "/path/on/s3/to/files/" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment