-
-
Save sahidursuman/2d2d4334f6d77a6d834521758ab6e605 to your computer and use it in GitHub Desktop.
PUT to S3 via cURL, Bash -- no external dependencies
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
#!/bin/bash | |
# usage ./s3.sh filename.ext remote/path/filename.ext | |
S3_KEY="REDACTED" | |
S3_SECRET="REDACTED" | |
S3_BUCKET="REDACTED" | |
REMOTE_PATH=$2 | |
date=$(date +"%a, %d %b %Y %T %z") | |
acl="x-amz-acl:public-read" | |
content_type='text/plain' | |
string="PUT\n\n$content_type\n$date\n$acl\n/${S3_BUCKET}/${REMOTE_PATH}" | |
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3_SECRET}" -binary | base64) | |
curl -X PUT -T $1 \ | |
-H "Host: ${S3_BUCKET}.s3.amazonaws.com" \ | |
-H "Date: $date" \ | |
-H "Content-Type: $content_type" \ | |
-H "$acl" \ | |
-H "Authorization: AWS ${S3_KEY}:$signature" \ | |
"https://${S3_BUCKET}.s3.amazonaws.com/${REMOTE_PATH}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment