OrderAndChaos
OrderAndChaos

Reputation: 3860

Having problems setting up AWS S3/Cloudfront with Symfony and LiipImagineBundle

I'm trying to set up AWS S3/Cloudfront to work with liipimaginebundle in Symfony, but I really have no idea what I'm doing.

So far I have tried the following documented here http://symfony.com/doc/current/bundles/LiipImagineBundle/cache-resolver/aws_s3.html:

Installed aws-sdk-php:

"require": {
    "aws/aws-sdk-php": "^3.28",
}

Set up my parameters (with the correct values not this dummy data):

amazon.s3.key:    "your-aws-key"
amazon.s3.secret: "your-aws-secret"
amazon.s3.bucket: "your-bucket.example.com"
amazon.s3.region: "your-bucket-region"

Set up a resolver (although I'm not sure what that even means). "%amazon.s3.cache_bucket%" is in the documentation but the parameter doesn't exist so I used "%amazon.s3.bucket%" instead:

liip_imagine:
    cache: profile_photos
    resolvers:
        profile_photos:
            aws_s3:
                client_config:
                    credentials:
                        key:    "%amazon.s3.key%"
                        secret: "%amazon.s3.secret%"
                    region: "%amazon.s3.region%"
                bucket: "%amazon.s3.bucket%" 
                get_options:
                    Scheme: https
                put_options:
                    CacheControl: "max-age=86400"

Added these lines to create the services:

services:
    acme.amazon_s3:
        class: Aws\S3\S3Client
        factory: Aws\S3\S3Client
        arguments:
            -
                credentials: { key: "%amazon.s3.key%", secret: "%amazon.s3.secret%" }
                region: "%amazon.s3.region%"

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

I'm currently getting this error when I run php bin/console server:run:

PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\UndefinedFunctionException: Attempted to call function "S3Client" from namespace "Aws\S3". in /var/www/swing-polls/var/cache/dev/appDevDebugProjectContainer.php:360

I've tried half a dozen other configs/tutorials to no avail. If someone can point me in the right direction I'd be incredibly grateful.

Using the code provided at Simple S3 Symfony Service with a few tweaks, I've been able to get my images to upload to my s3 bucket, but I just don't know how to get liipimaginebundle work with them.

Upvotes: 0

Views: 1123

Answers (1)

Dan Dumitriu
Dan Dumitriu

Reputation: 226

In vendor/liip/imagine-bundle/DependencyInjection/Compiler/ResolversCompilerPass.php you can see the CompilerPass is getting the value from "resolver" attribute of the tag and is using it to create a Reference object. This means the resolver should contain the id of a service.

Try replacing

 tags:
        - { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }

with

 tags:
        - { name: "liip_imagine.cache.resolver", resolver: "acme.amazon_s3" }

Upvotes: 0

Related Questions