无法在 S3 上创建存储桶

时间:2021-04-07 22:37:49

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

我正在使用 aws-sdk-php 库在 Linode 上处理 S3 服务器,但出于某种原因,我无法弄清楚我无法创建存储桶。已经创建了 2 个存储桶,我知道连接正在工作,因为我可以随意操作和处理这些存储桶。 但是,当我尝试创建新存储桶时,收到 400 错误消息。我的代码:

define('AWS_KEY', 'my-key');
define('AWS_SECRET_KEY', 'my-secret-key');
$ENDPOINT = 'http://eu-central-1.linodeobjects.com';
$client = new S3Client([
    'region' => 'eu-central-1',
    'version' => '2006-03-01',
    'endpoint' => $ENDPOINT,
    'credentials' => [
        'key' => AWS_KEY,
        'secret' => AWS_SECRET_KEY
    ],
    'use_path_style_endpoint' => true
]);
try {
    $result = $client->createBucket(['Bucket' => 'test']);
} catch (S3Exception $e) {
        echo $e->getMessage();
}

我尝试了以下调用 createBucket 方法的选项:

$result = $client->createBucket([
    'ACL' => 'private',
    'Bucket' => 'test', 
    'CreateBucketConfiguration' => [
        'LocationConstraint' => 'eu-central-1'
    ]
]);
$result = $client->createBucket([
    'Bucket' => 'test', 
    'LocationConstraint' => 'eu-central-1'
]);

无论我运行哪一个,我都会收到以下错误消息:

在“http://eu-central-1.linodeobjects.com/test”上执行“CreateBucket”时出错; AWS HTTP 错误:客户端错误:PUT http://eu-central-1.linodeobjects.com/test 导致 400 Bad Request 响应:InvalidLocationConstraintThe specified location-const (truncated...) InvalidLocationConstraint (client): The specified location-constraint is not valid - InvalidLocationConstraintThe specified location -约束无效testtx00000000000000a3d5d24-00606e2f87-1549e3f-default1549e3f-default-default

我对 PHP 中的这类事情不熟悉,这就是为什么我试图“按书”做所有事情(尽可能地遵循文档),所以我真的不明白发生了什么。

编辑:我发现了更多与此相关的问题。使用 Cyber​​Duck 我可以管理 S3,通过它我创建了一些存储桶(比如“测试”)。使用 aws-sdk-php 我可以使用 listBuckets 正确列出它们,甚至可以将对象放入其中,但是像 getBucketCors() 这样的一些函数会给出一条错误消息:

在“http://eu-central-1.linodeobjects.com/test?cors”上执行“GetBucketCors”时出错; AWS HTTP 错误:客户端错误:GET http://eu-central-1.linodeobjects.com/test?cors 导致 404 Not Found 响应:NoSuchCORSConfigurationtestNoSuchCORSConfigurationtesttx00000000000000a965dee-00606f69c5-1549e27-default1549e27-default-default

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题。 解决方案是将 region 参数从 eu-central-1 改回默认值 us-east-1。 之后,我可以创建存储桶。 我们的管理员告诉我,netapp 上的默认值也是 us-east-1,现在可以与 s3client 匹配。