AWS – S3 Bucket Integration with Laravel
Admin 24 July, 2020 0

AWS – S3 Bucket Integration with Laravel

While developing a great application, you should store the data of the application separate from the application. AWS S3 (Amazon Simple Storage Service) is best for storing data as it is quite affordable and stable. If you are building your application on the Laravel framework then it would be a great choice to work with cloud storage drivers.

While Amazon S3 is the best platform for storing static data for your application, still many developers find hard in configuring and customizing it. Henceforth, in this article, we have come with a complete guide by which you can understand how to work safely with data storage. Let’s begin now…

Setting Up AWS:

Firstly you need to set up AWS for creating and configuring everything.

1st Step: S3 bucket creation

If you already have a bucket that you require then you may skip this step. This is the easiest part. Firstly, log in to AWS Management console and then navigate to S3. In S3, there would be a create bucket option, click on that.

You need to set a name of the bucket which should be unique across all existing buckets in AWS S3. You also need to choose a region after then properties and permissions.

2nd Step: IAM Policy Creation:

Create a new policy by navigating to IAM and then into the Policy Tab.

You need to select a JSON Tab for inserting the following configuration:

{

            “Version”: “2012-10-17”,

            “Statement”: [

            {

            “Sid”: “VisualEditor0”,

            “Effect”: “Allow”,

            “Action”: [

                “s3:ListBucket”,

                “s3:GetBucketLocation”

            ],

            “Resource”: “arn:aws:s3:::bucket-name”

            },

            {

            “Sid”: “VisualEditor1”,

            “Effect”: “Allow”,

            “Action”: [

                “s3:PutObject”,

                “s3:GetObject”,

                “s3:DeleteObject”

            ],

            “Resource”: “arn:aws:s3:::bucket-name/*”

            },

            {

            “Sid”: “VisualEditor2”,

            “Effect”: “Allow”,

            “Action”: “s3:ListAllMyBuckets”,

            “Resource”: “*”

            }

            ]

}

** Change the name of the S3 bucket in the resource key**

Thereafter, you must return to the visual editor tab to detect if there is any error or warning signs. Click the Review Policy button if the things are fine.

Insert unique policy name and optionally some descriptive description, that can be helpful if you have a lot of custom policies

3rd Step:  IAM User Creation:

Go to the IAM Tab, and select User and then press on the button Add User.

Tick on the Programmatic Access, so the system would be able to generate a Key and Secret

Now you need to assign user permissions. There are template policies which grants too much access to the users, thus we are going to ignore them. The user would be able to access only the specific bucket that you have created. For this, you need to attach the existing policies and search for the policy you created earlier. In case you missed that step, you can create during this process by clicking Create policy. This will open a new tab in the browser to create a new policy.

You can select the policy from the list by ticking on the checkbox and then click on next.

Click Next: Review and then Create User.

You will get an Access Key ID and Secret access keys. These keys will be plugged into the config file.

Laravel Configuration:

You need to edit the environment variables of AWS from .env, which would be used by the configuration file.

After configuration of file system, you can test it.

Perfect! Now your S3 storage properly configured and you can use it!

Related post

On-Demand Mobile Apps – To Help During Corona-virus...
Increase your Online Presence this Quarantine by these...

0 comments

    Leave a Reply

    Name *

    Email *

    Comment *