0

I'm trying to get a list of objects from AWS using the S3fsService from the S3 File System module from within a hook_cron() implementation. The following code works:

// Fetch list of files in S3.
$config = \Drupal::config('s3fs.settings')->get();
$s3 = \Drupal\s3fs\S3fsService::getAmazonS3Client($config);
$iterator_args = ['Bucket' => $config['bucket']];
$iterator = $s3->getIterator('ListObjectVersions', $iterator_args);

…but I'm getting a message saying Deprecated function: Non-static method Drupal\s3fs\S3fsService::getAmazonS3Client() should not be called statically….

How should I be calling it differently?

Thanks!

1 Answer 1

2

You can access services via \Drupal::service('service.name').

You need to know the service's name to access it, though. Looking at the s3fs module, I can see in the module's s3fs.services.yml file that the class your requesting is available with the service name s3fs.

$s3fs = \Drupal::service('s3fs');
$result = $s3fs->getAmazonS3Client($config);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.