title: Can't access S3 bucket using IAM Role from an EC2 instance
body: <p>I'm trying to download a file from a private S3 bucket using the PHP SDK (on an EC2 instance).</p>
  
  <p>I create an IAM role and attached the <code>AmazonS3FullAccess</code> to it.</p>
  
  <p>I created the S3 bucket and this is the bucket policy:</p>
  
  <pre><code>{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": {
          "AWS": "arn:aws:iam::206193043625:role/MyRoleName"
        },
        "Action": [
          "s3:PutObject",
          "s3:GetObject",
          "s3:DeleteObject"
        ],
        "Resource": "arn:aws:s3:::config-files/*"
      }
    ]
  }
  </code></pre>
  
  <p>Then on the PHP side I make a curl request to <code>http://169.254.169.254/latest/meta-data/iam/security-credentials/MyRoleName</code>, I get a JSON back instantiate the S3Client and try to download it, but I'm getting this error message:</p>
  
  <blockquote>
    <p>Error executing "GetObject" on "<a href="https://files.s3.us-west-2.amazonaws.com/us-west-2__config.php" rel="nofollow noreferrer">https://files.s3.us-west-2.amazonaws.com/us-west-2__config.php</a>"; AWS HTTP error: Client error: <code>GET https://files.s3.us-west-2.amazonaws.com/us-west-2__config.php</code> resulted in a <code>403 Forbidden</code> response:</p>
    
    <p>AccessDenied</p>
    
    <p>Access DeniedC84D80 (truncated...) AccessDenied (client): Access Denied -</p>
    
    <p>AccessDenied</p>
    
    <p>Access DeniedC84D80DE6B2D35FD6sDWIYK98nSH+Oa8lBH7lD91rfHospDeo0jZKFDdo0CaeY8aX6Wb/s2ja5qeYxCBuLwDJ2AqSl0=</p>
  </blockquote>
  
  <p>Can anyone point me to a direction?</p>