2

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?

Pipe
  • 2,379
  • 2
  • 19
  • 33
  • 1
    Have a look at this [question.](https://stackoverflow.com/questions/34455410/error-executing-putobject-on-aws-upload-fails) Maybe it helps you. – Refilon Jun 18 '19 at 14:52
  • This [solution](https://stackoverflow.com/questions/34455410/error-executing-putobject-on-aws-upload-fails) works for me. – Ashiqur Rahman Jun 20 '19 at 08:28
  • @Refilon Just readed that question. i tried to read the bucket list with `$buckets = $this->s3->listBuckets(); foreach ($buckets['Buckets'] as $bucket) { echo $bucket['Name'] . "\n"; }` and it worked, it echoes the buckets available... so is not a problem with key or secret – Pipe Jun 20 '19 at 22:18
  • @AshiqurRahman your link is equal to Refilon link... any other idea? – Pipe Jun 20 '19 at 22:20
  • @Pipe 403 Forbidden errors with AWS are most likely to be 1) a problem with rights and policies 2) trying to access a non-existent folder. Can you be absolutely sure that it does not have to do with one of those? – Blackbam Jun 21 '19 at 11:17
  • @Pipe, would it be possible to get the exact version of the SDK you are using? Looking over [the `.changes/3.52.22` file](https://github.com/aws/aws-sdk-php/blob/master/.changes/3.52.22) in [the AWS PHP SDK GitHub repository](https://github.com/aws/aws-sdk-php), it seems that there was a bug fix in SDK version 3.52.22 which addressed a bug that was causing invalid signatures for S3 operations. I am just curious if you might be using a version that does not include that fix. – Spencer D Jun 21 '19 at 21:05
  • 1
    @SpencerD, i was using `v3.96.0`, just upgraded to `v3.101.0` and got the same error – Pipe Jun 25 '19 at 15:21
  • Just found the solution. I just posted it as an answer. FYI. – Pipe Jul 11 '19 at 20:43

1 Answers1

0

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.

Pipe
  • 2,379
  • 2
  • 19
  • 33