Configuring Symfony 2 for Gaufrette and Amazon S3

Posted on May 25, 2013

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 into app/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:

3 responses to “Configuring Symfony 2 for Gaufrette and Amazon S3”

  1. Vlad says:

    Hi! Thanks for post.
    I followed this steps, but got such error: “There is no extension able to load the configuration for “knp_gaufrette” (in /home/vladshut/projects/itezo/app/config/config.yml)”

    Do You know how to solve this problem? Thanks in advance.

  2. Chris says:

    The author forgot this step:
    Add this to your AppKernel.php:
    new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle()
    Instructions here are more up to date – I used a bit of both:

  3. 95Jolene says:

    Hello blogger, i must say you have very interesting content here.
    Your website can go viral. You need initial traffic boost only.
    How to get it? Search for: Mertiso’s tips go viral

Leave a Reply

Your email address will not be published. Required fields are marked *