admin管理员组

文章数量:1279212

I'm using AWS SDK for PHP (Version 3) to configure S3 bucket lifecycle rules via PutBucketLifecycleConfiguration. However, I’m getting the following error:

Aws\S3\Exception\S3Exception: Error executing "PutBucketLifecycleConfiguration" on "http://ceph:8000/testcachebucket?lifecycle"; AWS HTTP error: Client error: `PUT http://ceph:8000/testcachebucket?lifecycle` resulted in a `400 Bad Request` response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>InvalidRequest</Code><Message>Missing required header for this reques (truncated...)
 InvalidRequest (client): Missing required header for this request: Content-MD5 - <?xml version="1.0" encoding="UTF-8"?><Error><Code>InvalidRequest</Code><Message>Missing required header for this request: Content-MD5</Message><BucketName>testcachebucket</BucketName><RequestId>tx000000000000000000608-0067bc52d0-16f97-default</RequestId><HostId>16f97-default-default</HostId></Error>

According to the AWS documentation, the Content-MD5 header is required when making a REST API request. However, the PHP SDK documentation does not explain how to include it.

Here’s my current code:

$this->s3Client->PutBucketLifecycleConfiguration([
    'Bucket' => $bucket,
    'LifecycleConfiguration' => [
        'Rules' => $opts,
    ],
]);

How can I correctly make a request that includes the Content-MD5 header in AWS SDK for PHP?

I'm using AWS SDK for PHP (Version 3) to configure S3 bucket lifecycle rules via PutBucketLifecycleConfiguration. However, I’m getting the following error:

Aws\S3\Exception\S3Exception: Error executing "PutBucketLifecycleConfiguration" on "http://ceph:8000/testcachebucket?lifecycle"; AWS HTTP error: Client error: `PUT http://ceph:8000/testcachebucket?lifecycle` resulted in a `400 Bad Request` response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>InvalidRequest</Code><Message>Missing required header for this reques (truncated...)
 InvalidRequest (client): Missing required header for this request: Content-MD5 - <?xml version="1.0" encoding="UTF-8"?><Error><Code>InvalidRequest</Code><Message>Missing required header for this request: Content-MD5</Message><BucketName>testcachebucket</BucketName><RequestId>tx000000000000000000608-0067bc52d0-16f97-default</RequestId><HostId>16f97-default-default</HostId></Error>

According to the AWS documentation, the Content-MD5 header is required when making a REST API request. However, the PHP SDK documentation does not explain how to include it.

Here’s my current code:

$this->s3Client->PutBucketLifecycleConfiguration([
    'Bucket' => $bucket,
    'LifecycleConfiguration' => [
        'Rules' => $opts,
    ],
]);

How can I correctly make a request that includes the Content-MD5 header in AWS SDK for PHP?

Share Improve this question edited Feb 24 at 12:00 hakre 198k55 gold badges447 silver badges854 bronze badges Recognized by PHP Collective asked Feb 24 at 11:48 RoukmouteRoukmoute 7892 gold badges12 silver badges29 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Ok I finally found a "solution".
The problem comes from version of my Ceph server which is in Pacific version. Normally, middleware (ApplyChecksumMiddleware.php) should add this check automatically, but this is not the case on older Ceph servers like mine.

Indeed, AWS has modified its SDK to use CRC32 or SHA instead of MD5 in recent versions, making compatibility with Ceph Pacific problematic.

Solution:
To get around this problem, simply add the following constraint to composer.json to prevent the installation of incompatible versions of the SDK:

“conflict": {
    “aws/aws-sdk-php": ”^3.337”
}

This forces the use of an earlier version of the SDK that maintains the MD5 verification required by Ceph Pacific.

本文标签: aws php sdkAWS SDK PHP – How to add ContentMD5 for PutBucketLifecycleConfigurationStack Overflow