Skip to content

Instantly share code, notes, and snippets.

@tomasmuller
Created November 14, 2016 12:06
Show Gist options
  • Select an option

  • Save tomasmuller/1b5719a66ccd78a4570dd393b965ceee to your computer and use it in GitHub Desktop.

Select an option

Save tomasmuller/1b5719a66ccd78a4570dd393b965ceee to your computer and use it in GitHub Desktop.

Revisions

  1. tomasmuller created this gist Nov 14, 2016.
    18 changes: 18 additions & 0 deletions puts3.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/bin/bash
    file="$1"

    key_id="***AWS_ACCESS_KEY_ID***"
    key_secret="***AWS_SECRET_ACCESS_KEY***"
    path="your/path/$file"
    bucket="your-bucket"
    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 -v -i -X PUT -T $file http://$bucket.s3.amazonaws.com/$path \
    -H "Date: $date" \
    -H "Authorization: AWS $key_id:$sig" \
    -H "Content-Type: $content_type" \
    -H "Content-MD5: $md5"