Skip to content

Instantly share code, notes, and snippets.

@scottarthur
Created November 29, 2016 17:09
Show Gist options
  • Save scottarthur/46271b57fe5233c391d3084be101e146 to your computer and use it in GitHub Desktop.
Save scottarthur/46271b57fe5233c391d3084be101e146 to your computer and use it in GitHub Desktop.
Script to pull file from S3 via curl. Adapted from https://curl.haxx.se/mail/archive-2014-10/0006.html
#!/bin/bash
set -x
file='thirdparty/pool/main/d/datadog-agent/datadog-agent_1%3a5.10.0-1_amd64.deb'
bucket='sfdc-matrix-aptrepo'
resource="/${bucket}/${file}"
contentType="application/x-debian-package"
dateValue="`date +'%a, %d %b %Y %H:%M:%S %z'`"
stringToSign="GET
${contentType}
${dateValue}
${resource}"
s3Key=$AWS_ACCESS_KEY_ID
s3Secret=$AWS_SECRET_ACCESS_KEY
signature=`/bin/echo -n "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -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