11. Amazon S3

In order to use Amazon S3, you will need to require the following package:

composer require aws/aws-sdk-php

11.1. Configuration

This is a sample configuration to enable amazon S3 as a filesystem and provider:

# config/packages/sonata_media.yaml

sonata_media:
    cdn:
        server:
            path: 'http://%s3_bucket_name%.s3-website-%s3_region%.amazonaws.com'

    providers:
        image:
            filesystem: sonata.media.filesystem.s3

    filesystem:
        s3:
            bucket: '%s3_bucket_name%'
            accessKey: '%s3_access_key%'
            secretKey: '%s3_secret_key%'
            region: '%s3_region%'
            version: '%s3_version%' # defaults to "latest" (cf. https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_configuration.html#cfg-version)
            endpoint: '%s3_endpoint%' # defaults to null (cf. https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_configuration.html#endpoint)

11.2. Async adapter

In order to use async S3 adapter, you will need to require the following package:

composer require async-aws/simple-s3
# config/packages/sonata_media.yaml

sonata_media:
    filesystem:
        s3:
            async: true

Note

This bundle is currently using KNP Gaufrette as S3 adapter.

Note

Using “latest” for “sonata_media.filesystem.s3.version” in a production environment is not recommended because pulling in a new minor version of the SDK that includes an API update could break your production application.