I'm using AWS SDK for PHP (Laravel) and I'm trying to delete a S3 bucket with all the objects inside. Here is my code:
public function deleteBucket($syndcateid){
$s3client = AWS::createClient('s3');
$bucket = env('S3_BUCKET')."/syndcate-uploads/syndcate-".$syndcateid;
$listObjectsParams = ['Bucket' => $bucket];
$batchDelete = BatchDelete::fromListObjects($s3client, $listObjectsParams);
$batchDelete->delete();
$s3client->deleteBucket(array('Bucket' => $bucket));
$s3client->waitUntil('BucketNotExists', array('Bucket' => $bucket));
}
And when I run this code, I get the error:
Error executing \"ListObjects\" on \"https://s3-us-west-2.amazonaws.com/syndcate-media%2Fsyndcate-uploads%2Fsyndcate-32?delimiter=%2F&encoding-type=url\"; AWS HTTP error: Client error:
GET https://s3-us-west-2.amazonaws.com/syndcate-media%2Fsyndcate-uploads%2Fsyndcate-32?delimiter=%2F&encoding-type=urlresulted in a403 Forbiddenresponse:\n\nSignatureDoesNotMatchThe request signature we calcul (truncated...)\n SignatureDoesNotMatch (client): The request signature we calculated does not match the signature you provided. Check your key and signing method. - \nSignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.
Basically it is a SignatureDoesNotMatch error, and the reason its happening is, the slashes in the URL are not being decoded, as the requested URL (https://s3-us-west-2.amazonaws.com/syndcate-media%2Fsyndcate-uploads%2Fsyndcate-32) appears to have %2F instead of slashes.
I tried with the root bucket (no slashes), and it worked.
Any idea how to get the bucket name right ?