Skip to content

Amazon S3 Resolver

Edit this page

The AmazonS3Resolver resolver enables cache resolution using the \AmazonS3 storage API.

Deprecated, use the aws-s3 resolver instead. The legacy AmazonS3Resolver will be removed in version 3.

Dependencies

This cache resolver requires the aws-sdk-php library, which can be installed by executing the following command in your project directory:

1
composer require aws/aws-sdk-php

Configuration

To begin, you must assign your Amazon key, secret, and bucket to their respective parameters.

1
2
3
4
5
6
# app/config/config.yml or app/config/parameters.yml

parameters:
    amazon_s3.key:    "your-aws-key"
    amazon_s3.secret: "your-aws-secret"
    amazon_s3.bucket: "your-bucket.example.com"

Note

To not confuse the cache resolver, use the bucket.domain.tld notation. Specifying the bucket in a path (domain.tld/bucket) does not work.

Prerequisites

Next, you must define the required services.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# app/config/services.yml

services:

    acme.imagine.cache.resolver.amazon_s3:
        class: Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver
        arguments:
            - "@acme.amazon_s3"
            - "%amazon_s3.bucket%"
        tags:
            - { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }

    acme.amazon_s3:
        class: AmazonS3
        arguments:
            -
                key:    "%amazon_s3.key%"
                secret: "%amazon_s3.secret%"

Usage

After configuring AmazonS3Resolver, you can set it as the default cache resolver for LiipImagineBundle using the following configuration.

1
2
3
4
# app/config/config.yml

liip_imagine:
    cache: amazon_s3

Usage on a Specific Filter

Alternatively, you can set AmazonS3Resolver as the cache resolver for a specific filter set using the following configuration.

1
2
3
4
5
6
7
8
9
# app/config/config.yml

liip_imagine:
    filter_sets:
        cache: ~
        my_thumb:
            cache: amazon_s3
            filters:
                # the filter list

Tip

If you want to use other buckets for other images, simply alter the parameter names and create additional services.

Object URL Options

In order to make use of the object URL options, you can simply add a call to the service, to alter those options you need.

1
2
3
4
5
6
7
8
9
10
11
12
13
# app/config/services.yml

services:
    acme.imagine.cache.resolver.amazon_s3:
        class: Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver
        arguments:
            - "@acme.amazon_s3"
            - "%amazon_s3.bucket%"
        calls:
             # This calls $service->setObjectUrlOption('https', true);
             - [ setObjectUrlOption, [ 'https', true ] ]
        tags:
            - { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }

You can also use the constructor of the resolver to directly inject multiple options.

1
2
3
4
5
6
7
8
9
10
11
12
# app/config/services.yml

services:
    acme.imagine.cache.resolver.amazon_s3:
        class: Liip\ImagineBundle\Imagine\Cache\Resolver\AmazonS3Resolver
        arguments:
            - "@acme.amazon_s3"
            - "%amazon_s3.bucket%"
            - "public-read" # AmazonS3::ACL_PUBLIC (default)
            - { https: true, torrent: true }
        tags:
            - { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version