AWS SDK的PHP:从实例配置文件元数据服务器错误检索凭证 [英] AWS SDK for PHP: Error retrieving credentials from the instance profile metadata server

查看:551
本文介绍了AWS SDK的PHP:从实例配置文件元数据服务器错误检索凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想送SNS内留言到Android通过网络API。 下载并从<一个安装SDK href="http://aws.amazon.com/developers/getting-started/php/">http://aws.amazon.com/developers/getting-started/php/

I am trying to send SNS messeges to android through web api. Downloaded and installed the SDK from http://aws.amazon.com/developers/getting-started/php/

在运行sample.php得到以下错误:

Got following error while running sample.php:

Fatal error: Uncaught exception 'Aws\Common\Exception\InstanceProfileCredentialsException' with message '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] 28: Connection timed out after 5016 milliseconds [url] http://169.254.169.254/latest/meta-data/iam/security-credentials/)' in C:\xampp\htdocs\aws-php\vendor\aws\aws-sdk-php\src\Aws\Common\InstanceMetadata\InstanceMetadataClient.php:85 Stack trace: #0 C:\xampp\htdocs\aws-php\vendor\aws\aws-sdk-php\src\Aws\Common\Credentials\RefreshableInstanceProfileCredentials.php(52): Aws\Common\InstanceMetadata\InstanceMetadataClient->getInstanceProfileCredentials() #1 C:\xampp\htdocs\aws-php\vendor\aws\aws-sdk-php\src\Aws\Common\Credentials\AbstractRefreshableCredentials.php(54): Aws\Common\Credentials\Refreshable in C:\xampp\htdocs\aws-php\vendor\aws\aws-sdk-php\src\Aws\Common\InstanceMetadata\InstanceMetadataClient.php on line 85

有关此主题的一个小指南将帮助我很多

A little guidance on this topic will help me a lot

推荐答案

在我的情况,我用的是

return DynamoDbClient::factory(array(
  'version' => 'latest',
  'region'  => AWS_REGION,
  'key' => AWS_KEY,
  'secret'  => AWS_SECRET
));

这曾经是确定与 AWS / AWS-SDK-PHP 2.8.5版本,但是当作曲家自动安装3.2.0版本,我得到上述错误。这个问题很简单,我已经改变了我发出的呼吁的方式

which used to be ok with aws/aws-sdk-php version 2.8.5 , but when composer automatically installed version 3.2.0, I got the error above. The problem is simply that I should've changed the way I made the call to

return DynamoDbClient::factory(array(
  'version' => 'latest',
  'region'  => AWS_REGION,
  'credentials' => array(
    'key' => AWS_KEY,
    'secret'  => AWS_SECRET,
  )
));

作为记录<一个href="http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html#credential-profiles">here.在不改变通话时,的的Apache 的PHP是回落到寻找〜/ .aws /凭证文件中使用HOME环境变量,这是空。您可以通过将测试其值&LT; PHP的echo(GETENV(HOME));在 /var/www/test.php 例如和访问的链接的http://yourserver/test.php ,看到输出

as documented here. Without changing the call, the apache php was falling back to looking for the ~/.aws/credentials file using the HOME environment variable, which was empty. You can test its value by placing <?php echo(getenv("HOME")); in /var/www/test.php for example and accessing the link http://yourserver/test.php and seeing the output

是一个相关的帖子

这篇关于AWS SDK的PHP:从实例配置文件元数据服务器错误检索凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆