Access S3 bucket without ipv4 when setup S3 as the primary storage

AWS EC2
Nextcloud version: 27.1.2
Nginx 1.24.0
PHP 8.1.27

Recently Amazon AWS EC2 started to charge for public IPv4, so I removed my IPv4 to avoid that.
However, I found that my Nextcloud cannot access S3 storage anymore.
I use S3 as my primary storage, and it has been running well since 2019.
My config setting (related to S3) is as follows:

‘class’ => ‘\OC\Files\ObjectStore\S3’,
‘arguments’ =>
array (
‘bucket’ => ’ my bucket name’,
‘key’ => ‘my key’,
‘secret’ => ‘my secret’,
‘use_ssl’ => true,
‘region’ => ‘us-west-2’,
‘use_path_style’ => true,
),
),

If I assign a public IPv4 to the instance, then the service would be back to normal.
Please help me find the correct settings so that I can access S3 without a public IPv4.
Very appreciate!

Thanks for this information. I read these articles, but I still don’t know how to apply them correctly.
I was trying to use the following instructions:
# Configuring Object Storage as Primary Storage

In this article, I learned that Nextcloud can access Non-Amazon hosted S3.
So I tried to treat Amazon S3 as Non-amazon hosted S3, and revised the setting as follows:

‘objectstore’ => [
‘class’ => ‘\OC\Files\ObjectStore\S3’,
‘arguments’ => [
‘bucket’ => ‘my bucket’,
‘hostname’ => ‘s3.us-west-2.amazonaws.com’,
‘key’ => ‘my key’,
‘secret’ => ‘my secret’,
// required for some non-Amazon S3 implementations
‘use_path_style’ => true,
],
],

I still cannot access the files, however, some funny things happened.
With my original setting, Nextcloud would crash the php-fpm service and run very slowly.
With the above setting, Nextcloud can run faster (but still with no access to files: there is no file here).

I finally fixed the issue.
The config setting should be kept the same, and the following file needs to be revised.

./lib/private/Files/ObjectStore/S3ConnectionTrait.php

Find line 98 as follows:

$params[‘hostname’] = empty($params[‘hostname’]) ? ‘s3.’ . $params[‘region’] . ‘.amazonaws.com’ : $params[‘hostname’];

and change it to

$params[‘hostname’] = empty($params[‘hostname’]) ? ‘s3.dualstack.’ . $params[‘region’] . ‘.amazonaws.com’ : $params[‘hostname’];

Basically, you just need to add “dualstack.” after “s3.”
My Nextcloud service is normal now!!

1 Like

You shouldn’t need to adjust the code.

‘hostname’ => ‘s3.us-west-2.amazonaws.com’,

Did you try setting hostname in your config above to the s3.dualstack.us-west-2.amazonaws.com?

P.S. Either way, glad to hear you got it working!

I tested again and you are right.

  'objectstore' =>
  array (
    'class' => '\\OC\\Files\\ObjectStore\\S3',
    'arguments' =>
    array (
      'bucket' => 'my bucket',
      'hostname' => 's3.dualstack.us-west-2.amazonaws.com',
      'key' => 'my key',
      'secret' => 'mu secret',
      'use_ssl' => true,
      'region' => 'us-west-2',
      'use_path_style' => true,
    ),
  ),

The issue is that the following is necessary in the config, even if it is also in the hostname.

 'region' => 'us-west-2',

Thanks for your help!

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.