0
votes

I am trying to use the AWS PHP SDK to pre-sign V4 POST URLs and am hitting a major problem.

I have created a bucket called bucket1.chris.com. This has a CNAME to bucket1.chris.com.s3-eu-west-1.amazonaws.com.

When I create the S3Client I am passing http://bucket1.chris.com as the enpoint and bucket1.chris.com as the bucket name. Once the URL is signed and I get the action from the formAttributes it is:

bucket1.chris.com.bucket1.chris.com

Looking at the generateUri function in PostObjectV4 I can see this line:

// Use virtual-style URLs

$uri = $uri->withHost($this->bucket . '.' . $uri->getHost());

Which is causing my problem.

If I don't pass an endpoint I get:

s3-eu-west-1.amazonaws.com/bucket1.chris.com

(This is throwing an error: "The specified method is not allowed against this resource" when I try to use it but I think this might be something else)

Does anyone know how I you are supposed to use CNAME records (virtual hosted buckets) with the AWS PHP SDK?

1
s3-eu-west-1.amazonaws.com/bucket1.chris.com should have worked fine... perhaps it's because you've deleted it during testing, but at least for the moment, as I am writing this, there is no bucket in S3 called bucket1.chris.com.Michael - sqlbot
Thanks for your comment. See below for my own answer to this problem.Chris Mitchell

1 Answers

0
votes

I have figured out what I was doing wrong. I don't need to worry about passing an endpoint to the SDK since it is not used in the signing process.

The problem I was having with the s3-eu-west-1.amazonaws.zom/bucket1.chris.com was due to an issue with the bucket and not the endpoint I was using.