TGuimond TGuimond - 8 months ago 108
PHP Question

Access Denied - S3 resource using Pre Signed URL - PHP SDK

I am generating a Pre Signed URL to allow users to download files from an S3 Bucket. I am generating the URL's via the PHP SDK using the following code:

public static function get_content_link( $bucket, $key ) {

//check response code from AWS
require_once 'aws/aws-autoloader.php';

$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'eu-west-1',
'credentials' => [
'key' => 'MY-KEY',
'secret' => 'MY-SECRET',

$cmd = $s3->getCommand('GetObject', [
'Bucket' => $bucket,
'Key' => $key

$request = $s3->createPresignedRequest($cmd, '+500 minutes');

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

return $presignedUrl;

The URLs are being returned as expected, for example:

When I try to open any of the returned links in the browser I am getting an access denied error from S3:

<Message>Access Denied</Message>

The files that I want to provide access to are in a bucket which contains folders allowing public access, by the folder I am trying to access is private (called /product/). Our bucket policy looks like this:

"Version": "2008-10-17",
"Statement": [
"Sid": "AllowPublicReadProxies",
"Effect": "Allow",
"Principal": {
"AWS": "*"
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::MY-BUCKET-NAME/proxies*"
"Sid": "AllowPublicReadThumbs",
"Effect": "Allow",
"Principal": {
"AWS": "*"
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::MY-BUCKET-NAME/thumbs*"

It is my understanding that the purpose of creating a Pre Signed URL is to allow unauthenticated users temporary access to protected files without having to modify the bucket or folder permissions.

Has anyone got any ideas as to what I have missed or done wrong?


Answer Source

Many thanks to @Michael-sqlbot for figuring this out for me.

It turns out I was forcing the entire URL to be lowercase when outputting the pre signed URL to the page, so AWS was returning an Access Denied error due to the fact that the resource technically didn't exist.