【问题标题】:AWS v3 + PHP: Error retrieving credentials from the instance profile metadata serverAWS v3 + PHP:从实例配置文件元数据服务器检索凭证时出错
【发布时间】:2019-05-06 20:57:10
【问题描述】:

早上好,

我正在与 AWS 合作,以利用存储服务。 我基于版本 3,你可以在这里找到它: https://docs.aws.amazon.com/it_it/sdk-for-php/v3/developer-guide/getting-started_installation.html 使用 ZIP 文件安装!

我发现这个错误:

Uncaught exception 'Aws\Exception\CredentialsException' with message 'Error retrieving credentials from the instance profile metadata server. (cURL error 7: Failed connect to 169.254.169.254:80; No route to host (see http://curl.haxx.se/libcurl/c/libcurl-errors.html))' 

我的代码:

use Aws\S3\S3Client;
require_once 'aws-autoloader.php';
require_once 'config.php';

$config = array(
        'bucket' => BUCKET,
        'region'  => 'eu-west-3',
        'version' => 'latest',
        'credentials  ' => array('key'=>KEY,
                'secret'=>SECRET)
      );

$s3 = Aws\S3\S3Client::factory($config);
$objects = $s3->getIterator('ListObjects', ['Bucket' => $config['bucket'], 'Prefix' => 'challenge/']
);

我正在创建一个独立于 cms 或框架的函数。

有人知道怎么解决吗?

【问题讨论】:

    标签: php amazon-web-services curl amazon-s3 aws-sdk


    【解决方案1】:

    认为您的数组中的“凭据”键中有一些空格。

    'credentials ' => array('key'=>KEY, 'secret'=>SECRET)

    应该是

    'credentials' => array('key'=>KEY, 'secret'=>SECRET)

    编辑:尝试更新您的凭据以使用 Aws 的凭据对象

    $credentials = new Aws\Credentials\Credentials(AWS_ACCESS_KEY_ID ,AWS_SECRET_ACCESS_KEY);
    $config = array(
        'bucket' => BUCKET,
        'region'  => 'eu-west-3',
        'version' => 'latest',
        'credentials  ' => $credentials
      );
    

    【讨论】:

    • 谢谢,我更正了。不幸的是,这不是原因
    • 添加了其他东西来尝试,试一试:)
    猜你喜欢
    • 1970-01-01
    • 2018-04-18
    • 2017-11-25
    • 2015-02-08
    • 2021-12-27
    • 2019-05-25
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多