title: AWS PHP SDK S3: PutObject() Access Denied even though the SDK User Account has Full Permissions given
body: <p>While uploading a file into S3 Bucket, using this codes:</p>
  
  <pre><code>$s3Client = new S3Client([
      'version'     =&gt; 'latest',
      'region'      =&gt; 'ap-southeast-1',
      'credentials' =&gt; [
          'key'    =&gt; $keyName,
          'secret' =&gt; $keySecret,
      ],
  ]);
  
  try {
      $result = $s3Client-&gt;putObject([
          'Bucket' =&gt; 'web-uploads',
          'Key'    =&gt; 'sample.png',
          'Body'   =&gt; fopen('/var/www/html/images/sample.png', 'r'),
      ]);
  } catch (S3Exception $e) {
      echo $e-&gt;getMessage() . PHP_EOL;
  }
  </code></pre>
  
  <p>It shows below errors:</p>
  
  <pre><code>Error executing "PutObject" on "https://web-uploads.s3.ap-southeast-1.amazonaws.com/sample.png"; AWS HTTP error: Client error: `PUT https://web-uploads.s3.ap-southeast-1.amazonaws.com/sample.png` resulted in a `403 Forbidden` response:
  
  AccessDeniedAccess DeniedF43969 (truncated...)  AccessDenied (client): Access Denied -  AccessDeniedAccess DeniedF43969B3F3F0C85AS8k/6fBsY93ki6RbTQobjqIi6rgxtNqLhys5MbEg85oL4aPl/9IOwE4eNuSrVncFLZSl8JyZDN4=
  </code></pre>
  
  <p>At that point, my Bucket Permissions had the "Block public access" settings turned ON.</p>
  
  <p><strong>Only when I turned it OFF</strong>, like below:</p>
  
  <p><a href="https://i.stack.imgur.com/Z7g7j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z7g7j.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/shPvb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/shPvb.png" alt="enter image description here"></a></p>
  
  <p>.. <strong>then it worked</strong>. The upload was successful.</p>
  
  <p>But then, what is the point of creating a dedicated <strong>IAM User Account</strong>, with "Programmatic Access Type". And given FULL S3 PERMISSIONS to it, via it's Policy attached. Like below:</p>
  
  <p><a href="https://i.stack.imgur.com/b8a6v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b8a6v.png" alt="enter image description here"></a></p>
  
  <p>I was hoping the dedicated IAM account with sufficient permissions given (as mentioned above) would be all it needed for SDK. But apparently not, so far. This Policy definition is kinda totally ignored. I guess I could even delete the entire Policy attachment, and yet it would still work via above mentioned approach.</p>
  
  <p>But that's not what I expected.</p>
  
  <h2>My Question</h2>
  
  <p>What did I miss out to let PHP SDK successfully upload onto S3, without needing to allow <strong>Public Access</strong> in S3 Bucket's Permissions?</p>