Configure Amazon S3 on your Drupal website
As you already know Amazon Simple Storage Service (Amazon S3) is a scalable, high-speed, web-based cloud storage service. Storing files like images , videos in s3 bucket make faster delivery of web page content irrespective of their location of access.
Amazon Web Services (AWS) offers Simple Storage Service (S3) for scalable storage and content distribution, which can be integrated with Drupal sites running on your server.
Before you start-
Be sure that you have:
- An existing Drupal site or create one.
- Set up an account with Amazon Web Services (AWS). Amazon offers free access to most of their services for the first year.
- When creating an AWS account, you will have to enter credit card information. This is required, but you will not be charged unless you exceed the usage limits of their free tier
You will need to install below modules. The modules will provide configuration to add the AWS details.
S3 file system - Install the S3 File System module and AWS SDK version 3.x library using Composer.
composer require drupal/s3fs
S3 File System CORS -Use the S3 File System CORS Upload module to enhance your Drupal media handling and interface with your S3 bucket by having your file uploads go directly to your S3 bucket.
composer require drupal/s3fs_cors
Drupal Module Configuration-
You can configure the settings for the S3 File System module via the Drupal admin after the installation (admin/config/media/s3fs/settings).
Go to admin/config/media/file-system and set Default download method to Amazon Simple Storage Service. You can set the Upload destination to S3 File System within the Field Settings tab.
It is always recommended to keep your S3 configuration settings in your settings.php file since it is confidential. These are details that we get while creating AWS security details and S3 bucket.
In settings.php file add below details.
$settings['s3fs.access_key'] = '**************************';
$settings['s3fs.secret_key'] = '********************************';
$config['s3fs.settings']['bucket'] = 'buckwet-name';
$config['s3fs.settings']['region'] = 'ap-south-1';
$settings['s3fs.use_s3_for_public'] = FALSE;
$settings['s3fs.upload_as_private'] = TRUE;
Goto /admin/config/media/file-system and set the “Default download method” checkbox to “Amazon Simple Storage Service”.