Set up Amazon S3 as primary storage in Nextcloud

You would be amazed at how flexible Nextcloud is for everyone’s needs. When it comes to storage, Nextcloud allows you to use different storage mediums, such as on-disk or remote object storage. You may already know that Nextcloud supports various storage types as external storage, but setting them as primary storage is different. In this article, I am going to show you how to set up Amazon S3 as primary storage in Nextcloud.

What you need:

So let’s get started.

Create S3 bucket

The first thing we will do is create an S3 bucket. So, log in to the AWS console and go to S3 from the top left-hand side menu. Once there, click the Create new bucket button.

On the create bucket page, enter the bucket name. Choose ACLs enabled from the Object Ownership section, and select Object writer below (refer to the image below).

In the Block Public Access settings, leave it as is. The rest of the options can also be skipped.

aws-s3-bucket-creation

Note down the bucket name and region (eu-central-2 in my case).

Create new user in IAM

We need a user to access the bucket securely. For this, we will create a user without console access.

Go to IAM and click on Users. Then, click the Create new user button

Enter the new user’s username and click Next.

aws-iam-new-user

On this screen, search for the AmazonS3FullAccess policy and select it. Click Next.

aws-iam-choose-policy-for-new-user

Here, you can review your selections and input. Click Create user once confirmed.

aws-iam-review-new-user

Now, on the Users list page, click on the newly created user and then click Create access key.

aws-iam-new-user-details

Choose Application running outside AWS and click Next.

aws-iam-user-access-secret-keys

On the final screen, you will be presented with an Access key and a Secret key. Copy them somewhere safe, we will need them.

aws-iam-access-secret-keys-retrieval

Integrate with Nextcloud

Open the config.php file located in the Nextcloud config directory and paste the following into it, updating the information for the bucket and IAM user as needed.

'objectstore' => [
        'class' => '\\OC\\Files\\ObjectStore\\S3',
        'arguments' => [
                'bucket' => 'Nextcloud-bucket',
                'region' => 'eu-central-2',
                'key' => 'B25NSUAXASRYAP7P5KI',
                'secret' => 'a8INfsaumC+RMyGvrkUZAxz7DiuyyTJpJApNj',
        ],
],

Save and refresh your Nextcloud page. If everything you have entered is correct, S3 will now be connected.

Leave a Reply

Your email address will not be published. Required fields are marked *