Amazon S3 storage, getting started
My Zend2 application must store attachment files but we don't want to store them on a shared hosting. We can have files from multiple website, so I was searching for a cloud storage solution. Here we have Amazon S3, an alternative to Dropbox or other services like this. We can interact with the AWS platform using SDK for our favorite programming language after we have configured our account. So let's start with a recap:
Create the account
- Register or login on Amazon AWS
- The system will ask your credit card number. Don't worry, they will not ask you the CVV :)
- Insert all data and the system will ask you a PIN. You can ask an automatic call on your mobile phone and digit the PIN to complete the registration.
- You will receive a confirmation email and then you will be able to access the AWS console for the first time
First access to S3 storage
You will find S3 among the group of services "Storage & Content Delivery". After the first access, you can create your first bucket, directories and upload files. But you have to follow the best practice at least to recover your access key and secret access key. Amazon will ask you to access the AIM and create at least 1 user and 1 group, remove the root access key and other simple operations you'll read on your console. You can visit the best practice page.
If you need to use this service, the price table is encouraging for all companies. The money you spend for this service you will spend buying more space on your shared hosting for example. In this case it will not be the same and your space is always limited. The files on S3 will be always available and you have to worry only about manage your buckets and directories.
How to interact with S3 and store files
We must be able to use the console and the S3 service. We can create buckets, directories and upload files. We create buckets and the directories will stay inside a single bucket. This is useful because we can create a bucket for a single project and avoid confusion when we upload files using the SDK.
CORS and Client softwares
AWS must trust the source of data you are posting to an S3 bucket. Otherwise it will not accept any data for security reasons. To configure the CORS is not difficult. If you are using the client S3 browser on Windows, this is the link. Here you can even download the free and amazing software. Client softwares for Linux:
- S3 fox
- Cross FTP
- Cloud Explorer (github)
- S3 tools, with command line and multi-part upload. See this question and answers on stackoverflow
- Last but not least, you can even mount the S3 file system (FUSE) on your local machine. Here is the wikipedia for filesystem in userspace to get more informations and the github for the specific sf3-fc.
The next step
S3 is really simple to use. The trial account expires in 1 year and then you can decide if you must but some space. You will pay only for the used space on the cloud platform.