Skip to content

Instantly share code, notes, and snippets.

@codemedic
Created January 16, 2018 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codemedic/2d469b95a57db4d9d2bac8170635076f to your computer and use it in GitHub Desktop.
Save codemedic/2d469b95a57db4d9d2bac8170635076f to your computer and use it in GitHub Desktop.
Uploading files to S3 via bash with minimum deps (curl, openssl, base64)
#!/bin/bash
file="$1"
region="eu-west-1"
key_id="YOUR-AWS-KEY-ID"
key_secret="YOUR-AWS-KEY-SECRET"
path="some-directory/$file"
bucket="s3-bucket-name"
content_type="application/octet-stream"
date="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")"
md5="$(openssl md5 -binary < "$file" | base64)"
sig="$(printf "PUT\n$md5\n$content_type\n$date\n/$bucket/$path" | openssl sha1 -binary -hmac "$key_secret" | base64)"
curl -T $file http://$bucket.s3-$region.amazonaws.com/$path \
-H "Date: $date" \
-H "Authorization: AWS $key_id:$sig" \
-H "Content-Type: $content_type" \
-H "Content-MD5: $md5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment