Error retrieving credentials from the instance profile metadata server. Laravel s3

Question

The same code on almost identical servers fails locally and in production, however, it works on our intermediate server . When we try to interact with an element in a bucket, we get Error retrieving credentials.... - Both servers, production and production, are deployed by Envoyer and provided by Forge to AWS EC2 scripts. - Both copies fall into the same bucket with the same bucket policy. -.env settings are the same for everyone, minus server name and debugging

Production error:

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

Phased

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

Products

  • 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 example

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;
}
+4
2

. , EC2. . , IAM ~/.aws/credentials, . laravel, , laravel services.php.

config/services.php AWS IAM.   

'mailgun' => [
    'domain' => env('MAILGUN_DOMAIN'),
    'secret' => env('MAILGUN_SECRET'),
],

'ses' => [
    'key' => env('AWS_KEY'),
    'secret' => env('AWS_SECRET'),
    'region' => env('AWS_REGION'),
],

'sparkpost' => [
    'secret' => env('SPARKPOST_SECRET'),
],

'stripe' => [
    'model' => App\User::class,
    'key' => env('STRIPE_KEY'),
    'secret' => env('STRIPE_SECRET'),
],

, , .env AWS IAM, config/services.php.

.

+1

, .env AWS-, :

php artisan config:clear

, env, , , .

0

Source: https://habr.com/ru/post/1679898/


All Articles