当在PHP上使用带有IP的getIterator时,AWS S3Client解析错误的URL
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当在PHP上使用带有IP的getIterator时,AWS S3Client解析错误的URL相关的知识,希望对你有一定的参考价值。
由于某种原因,我无法使用S3Client的getIterator函数来反转URL。
而不是它寻找http://192.168.120.70/bucket
,它返回此:
Could not resolve host: bucket.192.168.120.70
我确定有一些简单的事情我正在忽略。
<?php
require '/Applications/MAMP/htdocs/lab/aws/aws-autoloader.php';
use AwsS3S3Client;
use AwsExceptionAwsException;
$bucketName = 'bucket';
$IAM_KEY = 'MY-KEY';
$IAM_SECRET = 'MY-SECRET';
// Connect to AWS
try {
$s3 = S3Client::factory(
array(
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET
),
'version' => 'latest',
'region' => 'eu-west-1',
'endpoint' => 'http://192.168.120.70/',
'profile' => 'MY-PROFILE'
)
);
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}
$buckets = $s3->listBuckets();
foreach ($buckets['Buckets'] as $bucket) {
echo $bucket['Name'] . "
";
}
// returns -> bucket
$obj = $s3->getIterator('ListObjects', array('Bucket' => 'bucket'));
foreach ($obj as $object) {
var_dump($object);
}
// Error -> Could not resolve host: bucket.192.168.120.70
?>
完整错误:
Fatal error: Uncaught exception 'AwsS3ExceptionS3Exception' with message 'Error executing
"ListObjects" on "http://bucket.192.168.120.70/?encoding-type=url";
AWS HTTP error: cURL error 6: Could not resolve host: bucket.192.168.120.70 (see
https://curl.haxx.se/libcurl/c/libcurl-errors.html)' GuzzleHttpExceptionConnectException: cURL
error 6: Could not resolve host: bucket.192.168.120.70
(see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in
/Applications/MAMP/htdocs/lab/aws/GuzzleHttp/Handler/CurlFactory.php:200 Stack trace: #0
/Applications/MAMP/htdocs/lab/aws/GuzzleHttp/Handler/CurlFactory.php(155):
GuzzleHttpHandlerCurlFactory::createRejection(Object(GuzzleHttpHandlerEasyHandle), Array) #1
/Applications/MAMP/htdocs/lab/aws/GuzzleHttp/Handler/CurlFactory.php(105):
GuzzleHttpHandlerCurlFactory::finishError(Object(GuzzleHttpHandlerCurlMultiHandler),
Object(GuzzleHttpHandlerEasyHandle), Object(GuzzleHttpHandlerCurlFactory)) #2
/Applications/MAMP/htdocs/lab/aws/GuzzleHttp/Han in
/Applications/MAMP/htdocs/lab/aws/Aws/WrappedHttpHandler.php on line 195
答案
这就是完成列出存储桶的目标所需要的。端点选项用于特定服务,在此场景中不需要:
$client = S3Client::factory(
array(
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET,
),
'region' => 'eu-west-1',
'version' => 'latest')
);
以上是关于当在PHP上使用带有IP的getIterator时,AWS S3Client解析错误的URL的主要内容,如果未能解决你的问题,请参考以下文章
在Python中,当在localhost上接受TCP套接字连接时,无法获得正确的对等体IP地址。
当在项目的 EditText 上调用 requestFocus() 时,RecyclerView 下降以启动
当在浏览器中输入 IP 地址怀疑 Ngnix 问题时,Amazon EC2 部署不工作
AWS s3 getIterator ListObjects 移动到另一台服务器后产生错误
当在docker容器中设置php时,如何在vscode中设置php可执行路径php.validate.executablePath?