title: AWS S3 - Setting Metadata with the PHP SDK2
body: <p>I am attempting to change the metadata of all of the objects in a particular bucket on S3 using the AWS PHP SDK2. I've had trouble finding a specific example using the new SDK, but have pieced together the following:</p>
  
  <pre><code>$OBJ_aws_s3 = S3Client::factory($config);
  
  $objects = $OBJ_aws_s3-&gt;getIterator('ListObjects', array(
      'Bucket' =&gt; $bucket,
      'MaxKeys' =&gt; 10
  ));
  
  foreach($objects as $object) {
      $key = $object['Key'];
  
      echo "Processing " . $key . "\n";
  
      $response = $OBJ_aws_s3-&gt;copyObject(array(
          'Bucket' =&gt; $bucket, 
          'Key' =&gt; $key,
          'CopySource' =&gt; $key,
          'Metadata' =&gt; array(
              'Cache-Control' =&gt; 'max-age=94608000',
              'Expires' =&gt; gmdate('D, d M Y H:i:s T', strtotime('+3 years'))
          ),
          'MetadataDirective' =&gt; 'REPLACE',
      ));
  }
  </code></pre>
  
  <p>The <code>foreach</code> loop successfully loops through the first 10 items in the given $bucket, but I get a 403 error on the <code>copyObject()</code> operation:</p>
  
  <pre><code>Uncaught Aws\S3\Exception\AccessDeniedException: AWS Error Code: AccessDenied, Status Code: 403
  </code></pre>
  
  <p>I am not sure if this is due to incorrect values being passed in to copyObject, or some setting in S3. Note that I have yet to create a rights-restricted account in IAM and am using the base account that should have all rights on the objects.</p>
  
  <p>Any help appreciated.</p>