适用于 PHP 的 AWS 开发工具包:从实例配置文件元数据服务器检索凭证时出错 [英] AWS SDK for PHP: Error retrieving credentials from the instance profile metadata server

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

问题描述

我正在尝试通过 web api 向 android 发送 SNS 消息.从 http://aws.amazon.com/developers/getting-started/php/<下载并安装了 SDK/a>

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 'AwsCommonExceptionInstanceProfileCredentialsException' 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 AwsCommonCredentialsCredentialsInterface object. ([curl] 28: Connection timed out after 5016 milliseconds [url] http://169.254.169.254/latest/meta-data/iam/security-credentials/)' in C:xampphtdocsaws-phpvendorawsaws-sdk-phpsrcAwsCommonInstanceMetadataInstanceMetadataClient.php:85 Stack trace: #0 C:xampphtdocsaws-phpvendorawsaws-sdk-phpsrcAwsCommonCredentialsRefreshableInstanceProfileCredentials.php(52): AwsCommonInstanceMetadataInstanceMetadataClient->getInstanceProfileCredentials() #1 C:xampphtdocsaws-phpvendorawsaws-sdk-phpsrcAwsCommonCredentialsAbstractRefreshableCredentials.php(54): AwsCommonCredentialsRefreshable in C:xampphtdocsaws-phpvendorawsaws-sdk-phpsrcAwsCommonInstanceMetadataInstanceMetadataClient.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 没问题,但是当 composer 自动安装版本 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,
  )
));

此处.在不更改调用的情况下,apache php 回退到使用空的 HOME 环境变量查找 ~/.aws/credentials 文件.您可以通过运行 php -r 'var_dump(getenv("HOME"));' 来检查它的值.

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 check its value by running php -r 'var_dump(getenv("HOME"));'.

这是一篇相关的帖子

This is a related post

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

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