Change base URL of generated S3 link using AWS SDK (PHP)

Viewed 1847

I want to create presigned S3 URL as mentioned here: https://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/s3-presigned-url.html

My code is quite similar to the example mentioned in the url:

$sdk = new Aws\Sdk( [
    'region' => 'eu-west-2',
    'version' => 'latest',
] );

$s3Client = $sdk->createS3();

$cmd = $s3Client->getCommand('GetObject', [
    'Bucket' => 'books.com',
    'Key'    => 'testKey'
]);

$request = $s3Client->createPresignedRequest($cmd, '+20 minutes');

// Get the actual presigned-url
$presignedUrl = (string) $request->getUri();

The above generates urls like so:

https://s3.eu-west-2.amazonaws.com/books.com/testKey?X-Amz-Content-Sha256=....

This is as expected. However my S3 bucket has Static Website Hosting and I use a CNAME record allowing me to use a different base url.

Therefore I want the following URL instead:

http://books.com/my-bucket/testKey?X-Amz-Content-Sha256=....

How can I do this?

1 Answers
Related