I will cover two areas here, why you would want to integrate S3 data storage with your Drupal site, and how to go about accomplishing that. The setup with Drupal is fairly straightforward, just requiring the installation of a well put together contributed module.
Why you might use Amazon S3 with Drupal:
Not having enough file storage or data transfer available on your web server is a good reason. Perhaps you need to store and share very large files, or maybe your web host charges a premium for overages past a certain amount of file storage and data transfer. The monthly rates for data storage with Amazon S3 is incredibly affordable for most organizations.
So, if your data needs are high enough, it might be more cost-effective to host your files on S3. Another reason is you might want to have a separate file storage area distinct from your web hosting environment, such as an EC2 instance. If you want to implement auto-scaling or load balancing with multiple clones of the same instance, you'll need to have this separate file storage area so that local files and uploaded images can be shared and retrieved from one place.
Otherwise, each clone of your server will have its own independent local files, which may end up being different from the others at different points in time. Website visitors which have their session residing on one server would get broken image links when trying to view an image that got uploaded by a user on a different instance.
How to integrate Amazon S3 into your Drupal website:
There are two different popular modules you can use to integrate S3 with your Drupal website, for public file storage purposes.
Method #1: Use the AmazonS3 module to override the Drupal Core file system with S3 storage.
It's a well put together module, unfortunately, the newest version can often require a patch of the Drupal core file system. This may be a deal breaker for some organizations as modifying core files should not be done lightly, and if you don't understand the ramifications probably not at all. To use the module, you'll want to review the installation instructions and familiarize yourself with using Composer.
Method #2: Use the Storage API module to integrate S3 storage with your Drupal website.
I really like this module, as it provides a nice layer to abstract the storage of files for your website while making it easy to shuttle off images and such to different containers for specific content types. The S3 access libraries are built into this module, so you won't have to set up separate configurations for it to integrate, which is a plus. However, the configuration of the module itself is a little more complex than just completely replacing file storage, the abstraction is probably the better approach in the long run.
Module configuration process:
- You will need to create a new storage container and storage class and assign them as appropriate to your content types.
- Create a new storage container, and set it to Amazon S3. You will need to provide an S3 bucket name and your AWS security access ID and secret key.
- Create a new storage class, set the initial storage location (save it locally first to reduce lag for users) and then set the final storage location, which in this case will be that new S3 storage container we just set up.
- Be sure to go back and update your content types so that their public download destination is assigned to the appropriate storage class, in this case, the one for S3.
Note: The reason you want the initial storage location to be local, is that there is a slight lag time when files are being uploaded, image-cached, and then transferred to S3. If you have lots of users trying to upload images at the same time this can be processing intensive. By having the initial upload local, you avoid this, and then when cron runs later Storage API will automatically transfer the file to S3 and then update the associations.