Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aholdsworth's avatar

Error retrieving credentials from the instance profile metadata server

Issue

The same code, on almost identical servers, fails locally and on production, however works on our staging server. When we attempt to interact with an item in a bucket, we get an Error retrieving credentials....

  • 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

Error on production:

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))

Server settings

Staging

  • Ubuntu 16.04.2 LTS on AWS
  • PHP 7.1.3-3
  • NPM 3.10.10
  • Node v6.10.1

Production

  • Ubuntu 16.04.1 LTS on AWS EC2
  • PHP 7.1.6-1
  • npm 3.10.10
  • Node v6.10.1

Composer.json packages

"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 sample

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')->get($fileKey); /* ****** FAILS HERE ****** */
    // stream bioPhoto
    header('Content-Type: image/jpeg');
    echo $contents;
}
0 likes
4 replies
cideaz's avatar

did you ever find a solution to this?

lemonpeak's avatar

I am also facing this issue can anyone help me ?

nandam's avatar

I am also facing same issue can anyone suggest me? i am using laravel 5.7 with windows 10

com1's avatar

In my case the reason was because I forgot to attach the IAM policy containing the required permissions to the EC2 instance in the AWS dashboard. You can find this in the security settings of the EC2 instance.

Please or to participate in this conversation.