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;
}