This post is more than a year old. The information, claims or views in this post may be out of date.
Laravel’s Filesystem component makes it very easy to work with cloud storage drivers, and the documentation does an excellent job of covering how the Storage facade works – so I won’t repeat that here.
Instead, here’s the specifics on getting Laravel configured to use S3 as a cloud disk. These instructions are valid as of 4 January 2017.
The AWS Setup
On the AWS side, you need a few things:
- An S3 bucket
- An IAM user
- An IAM policy attached to that user to let it use the bucket
- The AWS Key and Secret belonging to the IAM user
Step 1: The S3 Bucket
Assuming you don’t already have one, of course.
This is the easiest part – log into AWS, navigate to S3, and create a bucket with any given name. For this example, I’m using write500-backups (mainly because I just migrated the automated backups for write500.net to S3):

Then:

US Standard is otherwise known as North Virginia, and us-east-1. You can choose any region, but then you’ll need to use the corresponding region ID in the config file. Amazon keeps a list of region names here.
If you’re using this as a cloud disk for your app, it would make sense to locate the bucket as close as physically possible to your main servers – there are transfer time and latency benefits. In this case, I’m selecting Ireland because I like potatoes.
Step 2: The IAM User
Navigate to IAM and create a new user. AWS has made some updates to this process recently, so it has a lot more of a wizard look and feel.


Step 3: The IAM Policy
The wizard will now show the Permissions page. AWS offers a few template policies we’ll completely ignore, since they grant far too much access. We need our user to only be able to access the specific bucket we created.
Instead, we’ll opt to attach existing policies:

And then create a new policy:

This will pop out a new tab. On that screen, Select “Create Your Own Policy”.
- Policy name: Something unique
- Policy description: Something descriptive
- Policy document: Click here for the sample
Paste that gist into the Policy Document section, taking care that there are no blank spaces preceding the {. Replace “bucket-name” with your actual bucket name, then save:

Go back to the IAM wizard screen and click Refresh – you should see your brand new policy appear at the top of the list.

Tick the box, then click Next: Review, and then Create user. It’ll give you the Access key ID and Secret like so:

The Access Key ID (key) and Secret access key (secret) will be plugged into the config file.
Step 4: Configure Laravel
You’ll want to edit the filesystem details at:config/filesystem.php
Near the bottom you should see the s3 block. It gets filled in like so:

And done! The filesystem is now configured. If you’re making your app portable, it would be smart to use env() calls with defaults instead, but I’ll leave you figure that one out 🙂
Step 5: Test
The simplest way to test this is to drop into a tinker session and try working with the s3 disk.
And you should see the corresponding file in the S3 interface itself:
Step 6: 
Now that you have cloud storage configured, you should use it!.
First (and this will take minimal effort), you should set up the excellent spatie/laravel-backup package. It can do file and db backups, health monitoring, alerts, and can be easily scheduled. Total win.
You can also have Laravel do all its storage there. Just change the default disk:

This has the benefit of ensuring that even if your server crashes/dies horribly, nothing gets lost. You can also have multiple server instances all talking to the same s3 disk.
In my case, I’m using S3 as the storage for regular backups from write500. I’ll also use the same connection and attempt to publish my internal statistics dumps as CSV directly to S3 – meaning I can pull the data in via Domo’s Amazon S3 connector. I can then undo the SFTP setup I created previously, further securing my server.
You are the best one explain this in all search i did
LikeLiked by 1 person
Great article. You save my day 🙂
LikeLike
mmmm potatoes 🙂
LikeLike
nice tutorial, thank you!
LikeLike
Excellent article, it was working right out of the box with Leagues Flysystem.
LikeLiked by 1 person
Simple excellent article for a first timer with Amazon s3. Thank you so much.
LikeLike
Thumbs up! Great tutorial
LikeLike
Thank you very much !
LikeLike