Latheesan Latheesan - 3 years ago 196
PHP Question

How to access public AWS S3 bucket in laravel

I have a public S3 bucket called

(for example) in AWS in the

If I were to visit the following url in the browser (for example):

I get the following XML showing that I have one file in the bucket:

<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="">
<Prefix />
<Marker />

If I were to then visit I can download my file from my public bucket.

In order to achieve the same in my Laravel application; I first added this package via composer:


Then on my
I've added the following lines:


Lastly, I then tried to use the laravel filesystem to access the public s3 bucket file like this:

$json = Storage::disk('s3')->get('test.json');

When I did this; I got the following error:

Error retrieving credentials from the instance profile metadata
server. (cURL error 28: Connection timed out after 1000 milliseconds

So, I updated my
with some fake credentials:


Now I get this error:

Illuminate \ Contracts \ Filesystem \ FileNotFoundException

So my question is; firstly what am I doing wrong here? Is there no way to access a public s3 bucket in laravel without actually providing a valid S3 Key/secret? what if I don't know them? I only have the url to the public s3 bucket.

P.S. the
does not exist (it was a dummy bucket name to explain my problem, I do have a real public bucket I am trying to work with and it works fine in browser as explained above).

Answer Source

When you try to access it via the HTTPS URL, it works because it is public, and you're

When you try to access it via the SDK, it is trying to use the API to access it.

So either give your instance profile the correct permissions to access the bucket (which would no longer need to be public) or simply use an http client to retrieve the file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download