Search code examples
phpaws-php-sdk

S3 error access when upgrading AWS PHP SDK versions


I'm upgrading a system that uses aws-php-sdk v2 to aws-php-sdk v3.

In v2 i have something like:

$this->s3->upload($bucket, $key, $file, 'public-read');
//Where $this->s3 is a S3Client instance (from the SDK).

And it works well.

Now, after upgrading to aws-php-sdk v3, it throws an error:

Error executing "PutObject" on "https://s3.region.amazonaws.com/folder/file.ext".

Client error: PUT https://s3.region.amazonaws.com/folder/file.ext resulted in a 403 Forbidden response

The request signature we calculated does not match the signature you provided. Check your key and signing method.

Im using the same accessKey and secret that i used in v2 system.

As far as i know, is the PHP SDK that is responsible for signature calculation.. As i'm not doing any calculations manually.

What I'm doing wrong? Any ideas how to solve it?


Solution

  • Just found the answer to my problem.

    The problem was: in aws-php-sdk v2 I had this code:

    $bucket = "mybucketname/myfolder";
    $key = "myfilename.jpg";
    $upload = $this->app->S3->upload($bucket, $key, fopen( $local , 'rb'), 'public-read');
    

    This works well and it not shows any warnings/errors, but when upgrading to aws-php-sdk v3 it doesn't work. I just changed the $bucket and the $key values as:

    $bucket = "mybucketname";
    $key = "myfolder/myfilename.jpg";
    $upload = $this->app->S3->upload($bucket, $key, fopen( $local , 'rb'), 'public-read');
    

    And it just worked!

    Its really weird that it doesnt complain in v2 but in v3.