I have searched on the web for over two days now, and probably have looked through most of the online documented scenarios and workarounds, but nothing worked for me so far.
I am on AWS SDK for PHP V2.8.7 running on PHP 5.3. I am trying to connect to my S3 bucket with the following code:
// Create a `Aws` object using a configuration file
$aws = Aws::factory('config.php');
// Get the client from the service locator by namespace
$s3Client = $aws->get('s3');
$bucket = "xxx";
$keyname = "xxx";
try {
$result = $s3Client->putObject(array(
'Bucket' => $bucket,
'Key' => $keyname,
'Body' => 'Hello World!'
));
$file_error = false;
} catch (Exception $e) {
$file_error = true;
echo $e->getMessage();
die();
}
//
My config.php file is as follows:
<?php
return array(
// Bootstrap the configuration file with AWS specific features
'includes' => array('_aws'),
'services' => array(
// All AWS clients extend from 'default_settings'. Here we are
// overriding 'default_settings' with our default credentials and
// providing a default region setting.
'default_settings' => array(
'params' => array(
'credentials' => array(
'key' => 'key',
'secret' => 'secret'
)
)
)
)
);
It is producing the following error:
The request signature we calculated does not match the signature you provided. Check your key and signing method.
I've already checked my access key and secret at least 20 times, generated new ones, used different methods to pass in the information (i.e. profile and including credentials in code) but nothing is working at the moment.
After two days of debugging, I finally discovered the problem...
The key I was assigning to the object started with a period i.e. ..\images\ABC.jpg, and this caused the error to occur.
I wish the API provides more meaningful and relevant error message, alas, I hope this will help someone else out there!
I just experienced this uploading an image to S3 using the AWS SDK with React Native. It turned out to be caused by the
ContentEncoding
parameter.Removing that parameter "fixed" the issue.
In a previous version of the aws-php-sdk, prior to the deprecation of the
S3Client::factory()
method, you were allowed to place part of the file path, orKey
as it is called in theS3Client->putObject()
parameters, on the bucket parameter. I had a file manager in production use, using the v2 SDK. Since the factory method still worked, I did not revisit this module after updating to~3.70.0
. Today I spent the better part of two hours debugging why I had started receiving this error, and it ended up being due to the parameters I was passing (which used to work):I had to move the
catsinhats
portion of my bucket/key path to theKey
parameter, like so:What I believe is happening is that the
Bucket
name is now being URL Encoded. After further inspection of the exact message I was receiving from the SDK, I found this:Error executing
PutObject
onhttps://s3.amazonaws.com/awesomecatpictures%2Fcatsinhats/whitecats/white_cat_in_hat1.png
AWS HTTP error: Client error:
PUT https://s3.amazonaws.com/awesomecatpictures%2Fcatsinhats/whitecats/white_cat_in_hat1.png
resulted in a403 Forbidden
This shows that the
/
I provided to myBucket
parameter has been throughurlencode()
and is now%2F
.The way the Signature works is fairly complicated, but the issue boils down to the bucket and key are used to generate the encrypted signature. If they do not match exactly on both the calling client, and within AWS, then the request will be denied with a 403. The error message does actually point out the issue:
So, my
Key
was wrong because myBucket
was wrong.In my case the bucketname was wrong, it included the first part of the key (bucketxxx/keyxxx) - there was nothing wrong with the signature.
If none of the other mentioned solution works for you , then try using
this command will open a set of options asking for keys, region and output format.
Hope this helps!
I had to set
before with the ruby aws sdk v2 (there is probably something similiar to this in the other languages as well)