我正在尝试通过 web api 将 SNS 消息发送到 android。 从 http://aws.amazon.com/developers/getting-started/php/ 下载并安装 SDK
运行 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
关于这个主题的一些指导会对我有很大帮助
最佳答案
就我而言,我正在使用
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 版时,我得到了上面的错误。问题只是我应该改变打电话的方式
return DynamoDbClient::factory(array(
'version' => 'latest',
'region' => AWS_REGION,
'credentials' => array(
'key' => AWS_KEY,
'secret' => AWS_SECRET,
)
));
如文档所述 here .在不更改调用的情况下,apache php 回退到使用 HOME 环境变量查找 ~/.aws/credentials
文件,该变量为空。您可以通过运行 php -r 'var_dump(getenv("HOME"));'
.
This是一个相关的帖子
关于php - 适用于 PHP 的 AWS 开发工具包 : Error retrieving credentials from the instance profile metadata server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27400563/