title: Authenticate S3 request using Authorization header
body: <p>I would like to authenticate my S3 requests using this <a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#ConstructingTheAuthenticationHeader" rel="nofollow noreferrer">method</a>. For this purpose I have adapted scripts presented <a href="https://stackoverflow.com/questions/27658147/download-private-file-from-s3-using-bash">here</a>. Here is how it looks like:</p>
  
  <pre><code>#!/bin/sh
  file="$2"
  bucket="$1"
  resource="/${bucket}/${file}"
  contentType="$3"
  dateValue="`date +'%a, %d %b %Y %H:%M:%S %z'`"
  stringToSign="GET\n\n${contentType}\n${dateValue}\n${resource}"
  s3Key="$AWS_ACCESS_KEY"
  s3Secret="$AWS_SECRET_ACCESS_KEY"
  signature=`/bin/echo -en "$stringToSign" | openssl sha1 -hmac ${s3Secret} -binary | base64`
  curl -v -H "Host: ${bucket}.s3.amazonaws.com" -H "Date: ${dateValue}" -H "Content-Type: ${contentType}" -H "Authorization: AWS ${s3Key}:${signature}" https://${bucket}.s3.amazonaws.com/${file} 
  </code></pre>
  
  <p>My file permissions are like this:</p>
  
  <p><a href="https://i.stack.imgur.com/7KLEn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7KLEn.png" alt="enter image description here"></a></p>
  
  <p>and file content type is:</p>
  
  <p><a href="https://i.stack.imgur.com/gvmr2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gvmr2.png" alt="enter image description here"></a></p>
  
  <p>Here is how do I call my script:</p>
  
  <pre><code>./getfile1.sh tmp666 7b5879dd9b894f7fc5a14b895f01abd1.png image/png
  </code></pre>
  
  <p>Unfortunately I am getting <code>SignatureDoesNotMatch</code> error although <code>StringToSign</code> returned by AWS is matching mine:</p>
  
  <pre><code>&lt;StringToSign&gt;GET
  
  image/png
  Wed, 28 Sep 2016 12:46:14 +0200
  /tmp666/7b5879dd9b894f7fc5a14b895f01abd1.png&lt;/StringToSign&gt;
  </code></pre>
  
  <p>My IAM user has admin permissions. What am I doing wrong? I have spent half of day trying to solve it and feel powerless.</p>