Skip to content

Instantly share code, notes, and snippets.

@derwiki
Forked from chrismdp/s3.sh
Last active May 31, 2018 08:56
Show Gist options
  • Save derwiki/89210933e89f380a9d3321823f125337 to your computer and use it in GitHub Desktop.
Save derwiki/89210933e89f380a9d3321823f125337 to your computer and use it in GitHub Desktop.
PUT to S3 via cURL, Bash -- no external dependencies
#!/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