Skip to content

Instantly share code, notes, and snippets.

@xolian
Created October 11, 2021 16:16
Show Gist options
  • Save xolian/6afbd5f79b5249ce77a24196e075baf3 to your computer and use it in GitHub Desktop.
Save xolian/6afbd5f79b5249ce77a24196e075baf3 to your computer and use it in GitHub Desktop.
S3 Curl Uploads

Uploading to S3 in sh

file=/path/to/file/to/upload.tar.gz
bucket=your-bucket
resource="/${bucket}/${file}"
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