I am trying to download data from a AWS S3 server with their SDK for PHP, but at the second request it crashes with this error:
Fatal error: Uncaught Aws\S3\Exception\AccessDeniedException: AWS Error Code: AccessDenied, Status Code: 403, AWS Request ID...
This is my code:
use Aws\Common\Aws;
$aws = Aws::factory(
array(
'key' => 'my_key',
'secret' => 'my_secret',
)
);
$awsClient = $aws->get('s3');
$result = $awsClient->getObject(
array(
'Bucket' => 'my_bucket',
'Key' => 'my_key',
)
);
The first request works perfectly well, but the second time I call this, it crashes with the above Exception.
Does anyone know how to fix this?
Thank you very much.
I found myself the solution.
Turns out that I was sending an empty string to the second petition, in the key. AWS throws an Aws\S3\Exception\AccessDeniedException exception if it receives data it doesn't like.
It's good to know, though, so we can catch that exception, or control better the inputs.