简体   繁体   中英

getting error AWS HTTP error: cURL error 6: when creation bucket using 3.52 php sdk

I am using own cloud storage Rados s3 server and trying to create a bucket using 3.52 php AWS sdk. Following is the code I am running in my console:

    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'));

I am getting below fatal error

Fatal error: Uncaught exception 'Aws\\S3\\Exception\\S3Exception' with message 'Error executing "CreateBucket" on " http://pankaj.XXX.XX.XX.XXX/ "; AWS HTTP error: cURL error 6: Could not resolve host: pankaj.XXX.XX.XX.XXX; Name or service not known (see http://curl.haxx.se/libcurl/c/libcurl-errors.html )' in /var/www/html/object/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191

I think it's not accepting your end point which you define. please use add this key in your client connection 'use_path_style_endpoint' => true

Example :

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

Remove the endpoint from the client configuration.

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";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM