Skip to content

Instantly share code, notes, and snippets.

@raulanatol
Last active February 8, 2016 13:07
Show Gist options
  • Save raulanatol/bd4a57b14b8a7eaebfdc to your computer and use it in GitHub Desktop.
Save raulanatol/bd4a57b14b8a7eaebfdc to your computer and use it in GitHub Desktop.
Uploading to S3 (bash script)
#!/usr/bin/env bash
bucket=your-bucket
resource="/${bucket}/${file}"
file=/file_to_upload
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
s3Key=xxxxxxxxxxxxxxxxxxxx
s3Secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/${file}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment