AWS S3Client在PHP上使用带有IP的getIterator时解析错误的url
我无法使用S3Client的getIterator函数,因为它以某种方式反转了url 而不是寻找AWS S3Client在PHP上使用带有IP的getIterator时解析错误的url,php,amazon-web-services,amazon-s3,host,resolve,Php,Amazon Web Services,Amazon S3,Host,Resolve,我无法使用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 Aws\S3\S3Client;
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 Aws\S3\S3Client;
use Aws\Exception\AwsException;
$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'] . "\n";
}
// 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
?>
这就是实现列出存储桶的目标所需的全部内容。端点选项用于特定服务,在此场景中不需要:
$client = S3Client::factory(
array(
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET,
),
'region' => 'eu-west-1',
'version' => 'latest')
);
这就是实现列出存储桶的目标所需的全部内容。端点选项用于特定服务,在此场景中不需要:
$client = S3Client::factory(
array(
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET,
),
'region' => 'eu-west-1',
'version' => 'latest')
);
我觉得这是我的S3客户端创建中的一个问题,在这之后它起作用了。 奇怪的是,在我之前的代码中,只有第一个bucket不起作用
// Connect to AWS
try {
// You may need to change the region. It will say in the URL when the bucket is open
// and on creation.
$s3 = S3Client::factory(
array(
'version' => 'latest',
'region' => 'Standard',
'endpoint' => 'http://192.167.120.60/', // Needed in my case
'use_path_style_endpoint' => true, // Needed in my case
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET
)
)
);
} catch (Exception $e) {
// We use a die, so if this fails. It stops here. Typically this is a REST call so this would
// return a json object.
die("Error: " . $e->getMessage());
}
我觉得这是我的S3客户端创建中的一个问题,在这之后它起作用了。 奇怪的是,在我之前的代码中,只有第一个bucket不起作用
// Connect to AWS
try {
// You may need to change the region. It will say in the URL when the bucket is open
// and on creation.
$s3 = S3Client::factory(
array(
'version' => 'latest',
'region' => 'Standard',
'endpoint' => 'http://192.167.120.60/', // Needed in my case
'use_path_style_endpoint' => true, // Needed in my case
'credentials' => array(
'key' => $IAM_KEY,
'secret' => $IAM_SECRET
)
)
);
} catch (Exception $e) {
// We use a die, so if this fails. It stops here. Typically this is a REST call so this would
// return a json object.
die("Error: " . $e->getMessage());
}
根据我的经验,除了某些服务(MediaConvert),端点选项不是必需的。尝试删除终结点altogeter。请参见,您也不需要
'profile'=>'MY-profile'
,除非您连接到多个AWS帐户。感谢您提供有关配置文件的提示,似乎错误与此相关。根据我的经验,除了某些服务(MediaConvert)外,端点选项是不需要的。尝试删除终结点altogeter。请参见,您也不需要'profile'=>'MY-profile'
,除非您有多个连接到的AWS帐户。感谢您提供有关配置文件的提示,似乎错误与此相关。