AWS SDK PHP on S3 can't make a request using the web-browser

0

Hi there, I am a newbie and currently learning how to implement AWS SDK PHP for S3.
I have already installed composer and php on my EC2.
I have a simple php page on my EC2.

The workaround is, that when somebody from the Internet, requests my page => example.com/listbucket.php
It should print out all the buckets configured in the php page.

NOTE: If from my terminal execute, php listbucket.php i get the successful result and I can see all the buckets. So the S3Client is working right.
Here's the code from listbucket.php
---------------------------------------
$credentials = new Aws\Credentials\Credentials('123','123');
$s3Client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'eu-west-1',
'credentials' => $credentials,

]);

//Listing all S3 Bucket
$buckets = $s3Client->listBuckets();
foreach ($buckets [ 'Buckets' ] as $bucket) {
echo $bucket [ 'Name' ] . "\n";
}
---------------------------------------

The code works right but if I enable on the S3Client the debug => true , when I access listbucket.php from the browser It stops executing at the signin process.

-> Entering step sign, name 'signer'
------------------------------------

request.instance changed from 000000002056d0a7000000002d0e7df3 to 000000002056d0d1000000002d0e7df3
request.headers.x-amz-content-sha256 was set to array(1) {
[0]=>
string(64) "64BIT-STRING"
}

request.headers.X-Amz-Date was set to array(1) {
[0]=>
string(16) "20210415T144734Z"
}

request.headers.Authorization was set to array(1) {
[0]=>
string(211) "AWS4-HMAC-SHA256 Credential=[KEY]/20210415/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=[SIGNATURE]
}

---------------------------------------

It seems like when using the browser, I can't get the signin to work but when done from the terminal/cli from my EC2 instance it works!
How strange?

NOTE: I tried turning all the buckets accessible from everywhere and NOP!
NOTE: What I would like to achieve is printing out all the buckets when someone requests my page listbuckets.php.

Many, many thanks If you read everything!!
:)

Edited by: learner33 on Apr 15, 2021 10:04 AM

Edited by: learner33 on Apr 15, 2021 10:05 AM

Edited by: learner33 on Apr 15, 2021 10:07 AM

asked 3 years ago256 views
1 Answer
0

You need to create a pre-signed url.

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions