Configuring Symfony 2 for Gaufrette and Amazon S3

We’ve got a really big project that’s being built in Symfony 2. It’s going to be hosted on Amazon Web Services (AWS), so I looked into integrating S3 into our build. The KnpLabsGaufretteBundle seems to be the right choice for the job due to its clean abstraction, but getting it to actually run was a bit trickier than it should have been.

The Gaufrette documentation is, well, a bit lacking. Here’s how I got it to work:

  1. Add the following to your composer.json:
    "knplabs/knp-gaufrette-bundle": "0.2.*@dev",
    "amazonwebservices/aws-sdk-for-php": "dev-master",

    and run composer update.

  2. Add the following to app/config/config.yml:
                    amazon_s3_id: amazon.s3
                    bucket_name: %amazon.bucket%
                    create: true
                adapter: amazon
                    protocol: s3
                        - amazon
  3. Add the following to app/config/services.yml. If you don’t have one, create one and then go intoapp/config/config.yml and add an import line to the top.
            class: AmazonS3
                options: { key: %amazon.key%, secret: %amazon.secret%, certificate_authority: false, default_cache_config: true }
  4. Then go into app/config/parameters.yml and add the following in, putting in the proper values from your AWS account:
    amazon.key: YOUR_KEY
    amazon.secret: YOUR_SECRET
    amazon.bucket: YOUR_BUCKET
  5. And that should be it. From your code, you can access the bucket by using:
    Copy from

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s