早上好
我正在使用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或框架的函数。
有人知道如何解决吗?
答案 0 :(得分:2)
认为数组的“凭据”键中有一些空格。
'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
);