Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

S3 Client

Security covered Maintenance fixes only 53 sites

This module provides a factory to create an S3 client, intended for developers to integrate directly with S3 services for tasks like uploading, listing, and retrieving objects. It is not designed to integrate with Drupal's file system or provide a stream wrapper.

Overview

This is a developer-focused module that provides a simple factory for an S3 client.
It is not intended for integration with Drupal's file system and does not register a stream wrapper.
It is only intended for developers who wish to inject an S3 client factory into their services and then interact directly with the client to e.g. put, list and get objects from S3.

Installation

Install with composer, which will take care of fetching the AWS SDK.
composer require drupal/s3client

Configuration

There is no configuration or UI for the module, however you can declare credentials in your settings.php to support a default client.

$settings['s3client.default_key'] = 'YOUR KEY HERE';
$settings['s3client.default_secret'] = 'YOUR SECRET HERE';
$settings['s3client.default_region'] = 'us-east-1'; // Or your preferred region.

Typically this would be done with environment variables or a secrets management library.

$settings['s3client.default_key'] = getenv('S3_CLIENT_KEY');
$settings['s3client.default_secret'] = getenv('S3_CLIENT_SECRET');
$settings['s3client.default_region'] = getenv('S3_CLIENT_REGION'); // Or your preferred region.
// Advanced features for those using a service OTHER than AWS
$settings['s3client.default_endpoint'] = 'https://s3.example.com'; // Not required with AWS endpoint.
$settings['s3client.default_bucket_endpoint'] = TRUE; // If your endpoint is directly pointing to your bucket, you want to set this to TRUE. It has no effect if s3client.default_endpoint is undefined, default: FALSE.
$settings['s3client.default_version'] = 'latest'; // Default: 2006-03-01.

Usage

Default client

To inject the default client into your classes, use the s3client.s3client service.

In your services..yml

services:
  mymodule.something_s3:
    class: 'Drupal\mymodule\SomethingS3'
    arguments:
      - '@s3client.s3client'

Then you can interact directly with the client per the AWS documentation.

Injecting the factory

To inject the client factory into your classes, use the s3client.factory service.

In your services..yml

services:
  mymodule.something_s3:
    class: 'Drupal\mymodule\SomethingS3'
    arguments:
      - '@s3client.factory'

Then you can get a client as required using the createClient method like so

$client = $factory->createClient($key, $secret, $region);

// If you use a service other than AWS S3 you can also pass endpoint, bucket endpoint and version, see settings docs above.
$client = $factory->createClient($key, $secret, $region, $endpoint, $bucketEndpoint, $version);

Known problems

Please use the issue queue to report issues.

Drupal 10–11

Ask your assistant about S3 Client

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
4
Tracked since
Feb 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.2.0 Stable 10–11 Sep 11, 2025
1.1.0 Stable 10–11 PHP 8.1 Sep 2, 2024
1.x-dev Dev 10–11 PHP 8.1 Sep 2, 2024
1.0.1 Stable 8–10 Feb 3, 2023