从实例配置文件元数据服务器检索凭据时出错。Laravel S3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44703286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error retrieving credentials from the instance profile metadata server. Laravel S3
提问by Aaron Holdsworth
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 retrieving credentials...
. - 登台和生产服务器均由 Envoyer 部署并由 Forge 配置到 AWS EC2 实例。- 两个实例使用相同的存储桶策略命中同一个存储桶。- 所有的 .env 设置都相同,减去服务器名称和调试
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
- AWS 上的 Ubuntu 16.04.2 LTS
- PHP 7.1.3-3
- 新产品管理 3.10.10
- 节点 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
- AWS EC2 上的 Ubuntu 16.04.1 LTS
- PHP 7.1.6-1
- npm 3.10.10
- 节点 v6.10.1
Composer.json packages
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
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;
}
回答by wheelmaker
After ensuring your .env files contain the correct values for the AWS client, run the following command:
确保 .env 文件包含 AWS 客户端的正确值后,运行以下命令:
php artisan config:clear
php artisan config:clear
This should clear up your issue if it is caused by initially having incorrect or missing env data, not sure when the cache is updated on it's own but the config cache seems to be pretty persistent.
如果它是由于最初具有不正确或丢失的 env 数据引起的,这应该可以解决您的问题,不确定缓存何时自行更新,但配置缓存似乎非常持久。
回答by F. Dakia
I recently had this problem. In my case, it worked locally and not on the EC2instance. I did not understand too much. In the end I realized that I had set up IAMlocally in the default folder ~/.aws/credentials, so in local everything was good. So I poked in the laravel sources and I noticed that laravel was going to take the connection configs in the file services.phpconfig folder.
我最近遇到了这个问题。就我而言,它在本地运行,而不是在EC2实例上运行。我没太明白。最后我意识到我在默认文件夹 ~/.aws/credentials 中本地设置了IAM,所以在本地一切都很好。所以我查看了 laravel 的源代码,我注意到 laravel 将在文件services.phpconfig 文件夹中获取连接配置。
Edit config/services.php and put in the AWS IAM keys.
编辑 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'),
],
So I saw that my .env file did not have the AWS IAMlogin keys, those called in the config /services.php file.
所以我看到我的 .env 文件没有AWS IAM登录密钥,这些密钥在 config /services.php 文件中调用。
After a small adjustment everything works great.
稍作调整后,一切正常。
回答by thephper
I encountered this issue after I accedentially had entered the AWS_ACCESS_KEY_ID in the .env file twice.
我在 .env 文件中两次输入 AWS_ACCESS_KEY_ID 后遇到了这个问题。
.env:
.env:
AWS_ACCESS_KEY_ID=MYREALID
AWS_SECRET_ACCESS_KEY=myrealkey
...
...a lot of variables..
...
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
The AWS sdk therefor tries to search for these credentials elsewhere, at that's have the error occures.
为此,AWS sdk 尝试在其他地方搜索这些凭证,此时发生错误。
回答by 2Fwebd
This issue may occur if you are passing the wrong ENV variables, check your config/filesystems.php
:
如果您传递了错误的 ENV 变量,则可能会出现此问题,请检查您的config/filesystems.php
:
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
See: https://github.com/laravel/laravel/blob/master/config/filesystems.php#L60
参见:https: //github.com/laravel/laravel/blob/master/config/filesystems.php#L60
And make sure the keys are matchingin your .env
.
并确保密钥在您的.env
.
Pretty sure they changed the name in the last couple updates.
很确定他们在最近几次更新中更改了名称。