Skip to main content

Firstly, install the s3fs Drupal module and enable it on your local. Then go on to your AWS account, if you already don't have one create one and adding your billing details. It is important to add your billing details because otherwise you won't be able to use anything. even if it is in the free tier.

Once all that is done, search for S3 in services and go ahead and create a bucket. S3 bucket will be free for up to 5Gb for a year and then you'll have to pay 0.023 USD per GB. See more about AWS S3 pricing here.

You will have to configure the Drupal module to use your bucket, for this you need AWS credentials. Do NOT use your root account credentials for this although that will work. The correct way to do is create a new IAM account. Search for IAM in AWS console service, and go to Users section. There you can create a new user which is of type "Access key - Programmatic access". This means you will not be able to login as this user into your AWS account, but can be used for accessing various services like S3, SES etc. In the next screen, make sure to attach the policy: AmazonS3FullAccess for this user. Once the user is created, go to the "Security Credentials" tab in the user detail section and click on Generate Credentials to generate access key and secret for this user. Download them and keep them secure. You will be using these credentials to configure access to s3 bucket from your Drupal site using s3fs module.

Make sure to add this policy allowing public read on uploaded media items:

{
  "Version": "2012-10-17",
    "Statement": [
        {
          "Sid": "AllowPublicRead",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-bucket/*"
        }
    ]
}

In your Drupal site, go to /admin/config/media/s3fs and put the name of your bucket, region and all that. You can do all that in the settings.php file as well along with the credentials like below.

$settings['s3fs.access_key'] = 'AAAAAAAAAAAAAA';
$settings['s3fs.secret_key'] = 'zzzzzzzzzzzzaaaaaaaaqddddddd';
$config['s3fs.settings']['bucket'] = 'my-bucket';
$settings['s3fs.use_s3_for_public'] = TRUE;
$settings['s3fs.use_s3_for_private'] = FALSE;
$config['s3fs.settings']['region'] = 'us-east-2';
$settings['s3fs.upload_as_private'] = TRUE;
$settings['php_storage']['twig']['directory'] = '../private-files/storage/php';

Clear cache and you are done. You can test it from /admin/config/media/s3fs/actions by clicking on the Validate button.

x

Work

Therefore logo
80 Atlantic Ave, Toronto, ON Canada
Email: hello@therefore.ca
Call us: +1 4166405376
Linkedin

Let us know how we can help!