Last active
December 29, 2017 00:52
-
-
Save seanbehan/3c4b26fb3047f7550502f5f6e65bd903 to your computer and use it in GitHub Desktop.
Upload files to S3 via bash
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/sh | |
# | |
# Usage | |
# ./s3upload.bash path/to/file.txt name-of-file-on-s3.txt | |
# | |
file="$1" | |
path="$2" | |
key_id="s3 key goes here" | |
key_secret="s3 secret goes here" | |
bucket="bucket name goes here" | |
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 https://$bucket.s3.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
For public read of files in bucket add this as the bucket policy .. and rename NAME_OF_YOUR_BUCKET_GOES_HERE to your actual bucket name.