title: Error retrieving credentials from the instance profile metadata server. Laravel S3
body: <h1>Issue</h1>
  
  <p>The same code, on almost identical servers, fails locally and on production, however <strong>works on our staging server</strong>. When we attempt to interact with an item in a bucket, we get an <code>Error retrieving credentials...</code>.
  - Both servers, staging and production, are deployed by Envoyer and provisioned by Forge to AWS EC2 instances. 
  - Both instances hit the same bucket with the same bucket policy.
  - .env settings are same for all, minus the server name and debugging</p>
  
  <h1>Error on production:</h1>
  
  <pre><code>Aws\Exception\CredentialsException
  Error retrieving credentials from the instance profile metadata server. (cURL error 28: Connection timed out after 1003 milliseconds (see http://curl.haxx.se/libcurl/c/libcurl-errors.html))
  </code></pre>
  
  <h1>Server settings</h1>
  
  <h3>Staging</h3>
  
  <ul>
  <li>Ubuntu 16.04.2 LTS on AWS</li>
  <li>PHP 7.1.3-3</li>
  <li>NPM 3.10.10</li>
  <li>Node v6.10.1</li>
  </ul>
  
  <h3>Production</h3>
  
  <ul>
  <li>Ubuntu 16.04.1 LTS on AWS EC2</li>
  <li>PHP 7.1.6-1</li>
  <li>npm 3.10.10</li>
  <li>Node v6.10.1</li>
  </ul>
  
  <h3>Composer.json packages</h3>
  
  <pre><code>"laravel/framework": "5.4.*",       // 5.4.25
  "aws/aws-sdk-php-laravel": "~3.0",  // 3.1.0
  "guzzlehttp/guzzle": "~6.0",        // 6.2.3
  </code></pre>
  
  <h2>Code sample</h2>
  
  <pre><code>function getPhoto($personID)
  {
     $contents   = '';
     $id         = $personID;
     $cloudFront = env('AWS_CLOUDFRONT_PHOTO'); // d212rosgvhtylp.cloudfront.net
     $fileKey    = filePath($id) . '_t.jpg'; // 9ae299a1990e79d62f07c28bb60ecf6f_t.jpg
     $fileURL    = $cloudFront . '/' . filePath($id) . '_t.jpg'; // d212rosgvhtylp.cloudfront.net/9ae299a1990e79d62f07c28bb60ecf6f_t.jpg
     // check if in remote storage then get contents
     $contents = Storage::disk('s3photo')-&gt;get($fileKey); /* ****** FAILS HERE ****** */
     // stream bioPhoto
     header('Content-Type: image/jpeg');
    echo $contents;
  }
  </code></pre>