【发布时间】:2017-11-25 23:06:06
【问题描述】:
问题
相同的代码,在几乎相同的服务器上,在本地和生产中都失败了,但是在我们的登台服务器上工作。当我们尝试与存储桶中的项目交互时,我们会得到一个Error retrieving credentials...。
- 登台和生产服务器均由 Envoyer 部署并由 Forge 预置到 AWS EC2 实例。
- 两个实例使用相同的存储桶策略命中相同的存储桶。
- 所有的 .env 设置都是相同的,减去服务器名称和调试
生产错误:
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))
服务器设置
分期
- AWS 上的 Ubuntu 16.04.2 LTS
- PHP 7.1.3-3
- NPM 3.10.10
- 节点 v6.10.1
生产
- AWS EC2 上的 Ubuntu 16.04.1 LTS
- PHP 7.1.6-1
- npm 3.10.10
- 节点 v6.10.1
Composer.json 包
"laravel/framework": "5.4.*", // 5.4.25
"aws/aws-sdk-php-laravel": "~3.0", // 3.1.0
"guzzlehttp/guzzle": "~6.0", // 6.2.3
代码示例
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;
}
【问题讨论】:
-
+1 为您格式良好且描述清晰的问题。这对于新用户来说是一件难得的事情!继续努力:D
-
感谢您的帮助。我在发布之前看到了那篇文章,并进行了这些调整以匹配该代码。服务器仍在运行相同的代码库。