Note that when you create a bucket it is located in a specific region. The full list of regions is available here.
composer require aws/aws-sdk-php:^3.0
An example service definition of the Aws\S3\S3Client:
services:
acme.aws_s3.client:
class: Aws\S3\S3Client
factory: [Aws\S3\S3Client, 'factory']
arguments:
-
version: latest
region: %amazon_s3.region%
credentials:
key: %amazon_s3.key%
secret: %amazon_s3.secret%service_idThe service id of theAws\S3\S3Clientto use. (required)bucket_nameThe name of the S3 bucket to use. (required)detect_content_typeAuto detect the content type. (default false)optionsA list of additional options passed to the adapter.createWhether to create the bucket if it doesn't exist. (default false)directoryA directory to operate in. (default '') This directory will be created in the root of the bucket and all files will be read and written there.aclDefault ACL to apply to the objects
Once the service is set up use its key as the service_id in the gaufrette configuration:
# app/config/config.yml
knp_gaufrette:
adapters:
profile_photos:
aws_s3:
service_id: 'acme.aws_s3.client'
bucket_name: 'images'
detect_content_type: true
options:
directory: 'profile_photos'composer require aws/aws-sdk-php:^2.0
An example service definition of the Aws\S3\S3Client:
services:
acme.aws_s3.client:
class: Aws\S3\S3Client
factory: [Aws\S3\S3Client, 'factory']
arguments:
-
key: %amazon_s3.key%
secret: %amazon_s3.secret%
region: %amazon_s3.region%service_idThe service id of theAws\S3\S3Clientto use. (required)bucket_nameThe name of the S3 bucket to use. (required)detect_content_typeAuto detect the content type. (default false)optionsA list of additional options passed to the adapter.createWhether to create the bucket if it doesn't exist. (default false)directoryA directory to operate in. (default '') This directory will be created in the root of the bucket and all files will be read and written there.aclDefault ACL to apply to the objects
Once the service is set up use its key as the service_id in the gaufrette configuration:
# app/config/config.yml
knp_gaufrette:
adapters:
profile_photos:
aws_s3:
service_id: 'acme.aws_s3.client'
bucket_name: 'images'
detect_content_type: true
options:
directory: 'profile_photos'composer require amazonwebservices/aws-sdk-for-php
To use the Amazon S3 adapter you need to provide a valid AmazonS3 instance (as defined in the Amazon SDK). This can
easily be set up as using Symfony's service configuration:
# app/config/config.yml
services:
amazonS3:
class: AmazonS3
arguments:
options:
key: '%aws_key%'
secret: '%aws_secret_key%'amazon_s3_id: the id of the AmazonS3 service used for the underlying connectionbucket_name: the name of the bucket to useoptions: additional (optional) settingsdirectory: the directory to use, within the specified bucketregioncreate
Once the service is set up use its key as the amazon_s3_id in the gaufrette configuration:
# app/config/config.yml
knp_gaufrette:
adapters:
foo:
amazon_s3:
amazon_s3_id: amazonS3
bucket_name: foo_bucket
options:
directory: foo_directoryNote that the SDK seems to have some issues with bucket names with dots in them, e.g. "com.mycompany.bucket" seems to have issues but "com-mycompany-bucket" works.