Skip to content

Instantly share code, notes, and snippets.

@dmitryrck
Last active August 2, 2021 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitryrck/9640b00ca591ab6841d0838f90f5dc6b to your computer and use it in GitHub Desktop.
Save dmitryrck/9640b00ca591ab6841d0838f90f5dc6b to your computer and use it in GitHub Desktop.
#!/bin/bash
# I am not the author of this script.
# Unfortunately I don't remember where I copied from.
file="${1}"
bucket="${2}"
s3Key="${3}"
s3Secret="${4}"
resource="/${bucket}/${file}"
contentType="application/octet-stream"
dateValue="$(date -R)"
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
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