获取错误AWS HTTP错误:cURL错误6:使用3.52 php sdk创建存储桶时

时间:2018-02-09 04:26:49

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

我正在使用自己的云存储Rados s3服务器并尝试使用3.52 php AWS sdk创建一个存储桶。以下是我在控制台中运行的代码:

    require 'vendor/autoload.php';
    use Aws\S3\S3Client;
    use Aws\Credentials\CredentialProvider;
    $Connection = new S3Client([
    'region'      => 'us-west-2',
    'version'     => 'latest',
    'endpoint' => 'http://XXX.XX.XX.XXX',
    'credentials' => [
        'key'    => 'xx',
        'secret' => 'XX'
    ],
]);

//create a bucket
$promise =$Connection->createBucket(array('Bucket' => 'pankaj'));

我遇到致命错误

致命错误:未捕获异常'Aws \ S3 \ Exception \ S3Exception',消息'错误执行'CreateBucket“on”http://pankaj.XXX.XX.XX.XXX/“; AWS HTTP错误:cURL错误6:无法解析主机:pankaj.XXX.XX.XX.XXX;第191行的/var/www/html/object/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php中的名称或服务未知(参见http://curl.haxx.se/libcurl/c/libcurl-errors.html)'

2 个答案:

答案 0 :(得分:1)

我认为它不接受你定义的终点。 请在您的客户端连接中使用添加此密钥  ' use_path_style_endpoint' =>真正 示例:

$s3Client = new S3Client([
'region' => 'us-west-2',
'version' => '2006-03-01','use_path_style_endpoint' => true

]);

答案 1 :(得分:0)

从客户端配置中删除endpoint

require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;

$BUCKET_NAME='<BUCKET-NAME>';
//Create a S3Client
$s3Client = new S3Client([
    'region' => 'us-west-2',
    'version' => '2006-03-01'
]);
//Creating S3 Bucket
try {
    $result = $s3Client->createBucket([
        'Bucket' => $BUCKET_NAME,
    ]);
}catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}