正在尝试实例化ec2client w.r.t
$ec2Client = \Aws\Ec2\Ec2Client::factory(array(
'profile' => 'default',
'region' => 'us-west-2',
'version' => '2014-10-01'
));但失败并返回错误
Uncaught exception 'Aws\Common\Exception\CredentialsException' with message 'Could not load credentials.'我有:
cat ~/.aws/credentials
[default]
aws_access_key_id = xxxxxxxxxxx
aws_secret_access_key = xxxxxxxxxxx我正在通过composer "aws/aws-sdk-php": "3.*@dev"使用aws-sdk。
编辑1):我正在我本地的开发机器上尝试。
编辑2):我试过了:
use Aws\Common\Credentials\InstanceProfileProvider;
$profile= new InstanceProfileProvider(['profile'=>'default']);
$ec2Client = \Aws\Ec2\Ec2Client::factory(array(
'region' => 'us-west-2',
'version' =>'2014-10-01',
'credentials' => $profile
));这给了我不同的错误:
'Error retrieving credentials from the instance profile metadata server. When you are not running inside of Amazon EC2, you must provide your AWS Access Key ID and Secret Access Key in the "key" and "secret" options when creating a client or provide an instantiated Aws\Common\Credentials\CredentialsInterface object. (cURL error 28: Connection timed out after 1000 milliseconds)' in .. /InstanceProfileProvider.php:9 ..这给我的印象是,凭证配置文件仅在应用程序从AWS云实例中运行时才有效!这使得概要文件的想法变得无用(这适用于开发环境)
编辑3)
调试后发现,带有凭据配置文件的sdk似乎被破坏了,或者没有如预期的那样。credential profiles和environment variable都依赖于环境变量。如果禁用了环境变量,则这两个变量都将失败。
可能的解决方法:
a) Enable environment variables
b)设置HOME evn变量
putenv('HOME=/Users/yourname');
$ec2Client = \Aws\Ec2\Ec2Client::factory(array(
'region' => 'us-west-2',
'version' => '2014-10-01'
));Profile init()函数具有文件名选项,但除了HOME env变量之外,没有其他明显的方法来传递凭据配置文件路径
Aws\Common\Credentails\Profiler->init()
public static function ini($profile = null, $filename = null){
...
}同样,如果您无法读取/Users/yourname/.aws/credentials文件,则必须稍微调整它
chmod 644 /Users/yourname/.aws/credentials
发布于 2015-03-05 22:34:39
您应该将.aws/credentials文件放在web服务的根目录中,而不是放在ssh用户的根目录中
发布于 2015-06-10 23:27:59
您必须将.aws/credentials文件与您的配置放在web服务的主目录中。
将此文件放入网站的某个PHP文件中
echo getenv('HOME');然后在该目录中:
mkdir .aws
touch credentials
nano credentials在那里你必须粘贴内容(不需要在键中加引号):
[default]
aws_access_key_id = xxxxxxxxxxx
aws_secret_access_key = xxxxxxxxxxx这应该就行了!
编辑:正如sakhunzai在评论中所说(谢谢!),echo getenv(' HOME ')有时会返回null,如果发生这种情况,他提供了这样的解决方案:“然而,从命令行php -i |grep home给我正确的用户主目录。”
所以请记住这一点。
https://stackoverflow.com/questions/27705783
复制相似问题