What is Amazon S3?
The Amazon Simple Storage Service (Amazon S3) is a scalable, high-speed, low-cost Web-based service designed for online backup and archiving of data and application programs.
Amazon Simple Storage Service (Amazon S3) is simple storage for the Internet. You can configure it very simply and quickly in the AWS console. In S3, there’s no initial charges, zero set-up cost. You only pay for what you utilize. Unlimited storage and bandwidths, pay as you use, full control on file privacy are the most key features of S3. Amazon S3 also provides options to host static websites.
Why I find Amazon S3 great?
Most of the Websites are having Dynamic contents which will be having many Images, Videos and Audio, etc. These images will be either uploaded by the Users or the Admin of the website. Some websites will be having hundreds or even thousands of images depending on the Market they are focused on. Storing the whole images inside Server will run out of the disk space and causes issues to the server. So it will be good to save it directly in the Amazon S3.
How to Configure Amazon S3?
Amazon S3 is very simple to configure and use. This can be configured from the AWS console.
In S3 you can create Buckets, Buckets are very similar to Folders in our PC, It helps us to organise the files. S3 generates random URLs for each and every files uploaded to it. Each files is objects in S3. These objects can be accessed from the Web. S3 provides you different policies and permissions to secure the contents stored in it.
Amazon Web Service (AWS) console provides you the ability to create IAM user. IAM user this the centralised user account provided by the AWS in order to access the AWS service remotely or through API calls, etc.
When we are using PHP code and if we wanted to access the objects from the S3 need to use IAM user credentials to get the object from S3 bucket if we not allowed public access to that object.
How S3 is used with a PHP web application?
As we have already mentioned that the S3 can be used for storing the static contents like Pictures, Videos, Audio, etc. Let us see how it work in a real work scenario.
As the Image displays when a user is trying to access the Webpage, The requests hits the Web-Server. The Web-Server sends a request to the Amazon S3 asking for a Image stored in it and the S3 returns the Image that is used in that Web-page.
How to set up?
Let us assume that we have a Web server running. We have a PHP site running in it and expecting thousands of images in it. We need to make sure the will be no storage issue by filling the hard drive.
Choose the following steps to mount S3 on an EC2 instance.
- Create a new directory under that webroot of the PHP Application where you wanted to mount the static contents.
- Now you need to download and install s3fs from the source. S3fs is used to mount the S3 bucket to the system.
- In-order to connect to the Amazon S3 bucket we need to authenticate. For that we need to create .passwd-s3fs inside the user home directory and pass the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY which we got from the AWS console.
- Now that after mounting the Drive we can starting using it as a local drive attached to the PC.
What are the PROS /CONS of using S3?
We understood Amazon S3 and its features, also how we can configure it. Now let us discuss the Advantage/Disadvantage of using S3. In the perspective of a web application.
1. S3 is that it can be mounted to an EC2 instance and can act as a local drive attached to a system.
2. S3 can be used as a Backup Volume where we can store the backups. This can save the EBS (Elastic Block Storage) space which is the main storage.
3. S3 can be used for many servers at same time. Whereas EBS can only attached to a instance at a time.
4. Highly Available, Redundant. Basically data loss is not possible (99.999999999% durability, 99.9 uptime SLA).
5. S3 storage provides upto 5TB storage space.
1. S3 is an object store it is not a file system.
2. Hence S3 is not a file system it does not have file-system permissions.
3. S3 is slower than the EBS volume which is directly connected to the instance. Hence it is good to store static contents like Photos, Videos, etc.
Amazon S3 is the best way to Host web sites cost-effectively. Since the price of physical drives like is huge Amazon S3 will be good enough to store the static contents.