title: AWS S3 access denied when getting image by url
body: <p>I am working on <strong>AWS EC2 Ubuntu Machine</strong> and trying to fetch image from <strong>AWS S3</strong> but following error has been shown to me every time.</p>
  
  <pre><code>&lt;Error&gt;
  &lt;Code&gt;InvalidArgument&lt;/Code&gt;
  &lt;Message&gt;
  Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4.
  &lt;/Message&gt;
  &lt;ArgumentName&gt;Authorization&lt;/ArgumentName&gt;
  &lt;ArgumentValue&gt;null&lt;/ArgumentValue&gt;
  &lt;RequestId&gt;7C8B4BF1CE2FDC9E&lt;/RequestId&gt;
  &lt;HostId&gt;
  /L5kjuOET4XFgGter2eFHX+aRSvVm/7VVmIBqQE/oMLeQZ1ditSMZuHPOlsMaKi8hYRnGilTqZY=
  &lt;/HostId&gt;
  &lt;/Error&gt;
  </code></pre>
  
  <p><strong>Here is my bucket policy</strong></p>
  
  <pre><code>{
   "Version": "2012-10-17",
   "Id": "Policy1441213815928",
   "Statement": [
    {
     "Sid": "Stmt1441213813464",
     "Effect": "Allow",
     "Principal": "*",
     "Action": "s3:GetObject",
     "Resource": "arn:aws:s3:::mytest.sample/*"
    }
   ]
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AgfBs.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AgfBs.png" alt="enter image description here"></a></p>
  
  <p><strong>Here is the code</strong></p>
  
  <pre><code>require 'aws-autoloader.php';
  
  $credentials = new Aws\Credentials\Credentials('key', 'key');
  $bucketName = "mytest.sample";
  $s3 = new Aws\S3\S3Client([
      'signature' =&gt; 'v4',
      'version' =&gt; 'latest',
      'region' =&gt; 'ap-southeast-1',
      'credentials' =&gt; $credentials,
      'http' =&gt; [
          'verify' =&gt; '/home/ubuntu/cacert.pem'
      ],
      'Statement' =&gt; [
          'Action ' =&gt; "*",
      ],
  
    ]);
  
  $result = $s3-&gt;getObject(array(
  'Bucket' =&gt; $bucketName,
  'Key' =&gt; 'about_us.jpg',
      ));
  </code></pre>
  
  <p><strong>Html</strong></p>
  
  <pre><code>&lt;img src="&lt;?php echo $result['@metadata']['effectiveUri']; ?&gt;" /&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>Edit</strong> for Michael - sqlbot : here I am using default KMS.</p>
  </blockquote>
  
  <pre><code>   try {
          $result = $this-&gt;Amazon-&gt;S3-&gt;putObject(array(
              'Bucket' =&gt; 'mytest.sample',
              'ACL' =&gt; 'authenticated-read',
              'Key' =&gt;  $newfilename,
              'ServerSideEncryption' =&gt; 'aws:kms',
              'SourceFile' =&gt; $filepath,
              'ContentType' =&gt; mime_content_type($filepath),
              'debug' =&gt; [
                  'logfn' =&gt; function ($msg) {
                      echo $msg . "\n";
                  },
                  'stream_size' =&gt; 0,
                  'scrub_auth' =&gt; true,
                  'http' =&gt; true,
              ],
          ));
      } catch (S3Exception $e) {
          echo $e-&gt;getMessage() . "\n";
      }
  </code></pre>
  
  <p>let me know if you need more.</p>