【问题标题】:PHP AWS SDK 3 Error: AWS HTTP error: cURL error 6: Could not resolve host: s3.oregon.amazonaws.comPHP AWS SDK 3 错误:AWS HTTP 错误:cURL 错误 6:无法解析主机:s3.oregon.amazonaws.com
【发布时间】:2017-02-20 19:30:33
【问题描述】:

我正在尝试连接到 AWS 版本 3 SDK 存储桶。

但是,我收到以下错误:

PHP 致命错误:未捕获的异常 'Aws\S3\Exception\S3Exception' 并带有消息“在“https://s3.oregon.amazonaws.com/my-buekct-test/hello_world.txt”上执行“PutObject”时出错; AWS HTTP 错误:cURL 错误 6:无法解析主机:s3.oregon.amazonaws.com(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)'

这是我的代码,很简单。

<?php
header('Content-Type: text/plain; charset=utf-8');

// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';

$s3 = new Aws\S3\S3Client([
'region'  => 'Oregon',
'version' => 'latest',
'credentials' => [
    'key'    => 'Enter the key',
    'secret' => 'Enter the Secret key'
]
]);

// Send a PutObject request and get the result object.
$key = 'hello_world.txt';

$result = $s3->putObject([
'Bucket' => 'my-buekct-test',
'Key'    => $key,
'Body'   => 'this is the body!'
]);

// Print the body of the result by indexing into the result object.
echo $result['Body'];

我正在使用 AWS centos、php 5.5.21、apache 2.4.10

你能帮忙指出我哪里做错了吗?

【问题讨论】:

    标签: php amazon-s3


    【解决方案1】:

    尝试使用以下代码,您只需更改区域

    <?php
    header('Content-Type: text/plain; charset=utf-8');
    
    // Include the SDK using the Composer autoloader
    require 'vendor/autoload.php';
    
    $s3 = new Aws\S3\S3Client([
    'region'  => 'us-west-2',
    'version' => 'latest',
    'credentials' => [
        'key'    => 'Enter the key',
        'secret' => 'Enter the Secret key'
    ]
    ]);
    
    // Send a PutObject request and get the result object.
    $key = 'hello_world.txt';
    
    $result = $s3->putObject([
    'Bucket' => 'my-buekct-test',
    'Key'    => $key,
    'Body'   => 'this is the body!'
    ]);
    
    // Print the body of the result by indexing into the result object.
    echo $result['Body'];
    

    'region' => 'us-west-2', // 这个东西我只更新了

    你可以从这里找到aws的区域信息:http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-26
      • 2019-05-19
      • 1970-01-01
      • 2019-12-19
      • 1970-01-01
      • 2011-05-20
      • 2018-07-19
      • 2019-05-04
      相关资源
      最近更新 更多