spacecatninja / craft-imager-x

Image transforms, optimizations and manipulations for your Craft CMS site.
Other
26 stars 16 forks source link

AWS S3 Region Missing #241

Open pimago opened 1 year ago

pimago commented 1 year ago

I'm submitting a...

Description

I am gettin these missing region errors when I try to transform images from S3. The default craft transforms are working fine.

Displayed errors, stack trace, relevant logs

A "region" configuration value is required for the "s3" service
(e.g., "us-west-2"). A list of available public regions and endpoints can be
found at http://docs.aws.amazon.com/general/latest/gr/rande.html. {"memory":7425008} 
2023-10-02 12:01:27 [web.ERROR] [spacecatninja\imagerx\services\StorageService::store] An error occured when trying to upload file "/var/www/html/web/imager/images/3028/dealerofdecaythumb-Kopie-2_398ca7b8debe49bfbe7d47514c01e3d7.webp" to external storage "aws". The transformed file has been deleted. {"memory":7391000} 
2023-10-02 12:01:27 [web.ERROR] [spacecatninja\imagerx\externalstorage\AwsStorage::upload] Invalid configuration of S3 Client: Missing required client configuration options:

my aws config for imager

'storageConfig' => [
        'aws' => [
            'accessKey' => App::env('S3_KEY_ID'),
            'secretAccessKey' => App::env('S3_SECRET'),
            'region' => App::env('S3_REGION'),
            'bucket' => App::env('S3_BUCKET'),
            'folder' => 'imager',
            'requestHeaders' => array(),
            'storageType' => 'standard',
            'public' => false,
            'cloudfrontInvalidateEnabled' => true,
            'cloudfrontDistributionId' => App::env('CLOUDFRONT_DISTRIBUTION_ID'),
        ]
    ]

Region is eu-central-1

Additional info

aelvan commented 1 year ago

Hi,

Have you double checked that eu-central-1 is in fact where the bucket is located? A common mistake is to mix the region that the AWS console is using with the region of the bucket. Ie, check the list of buckets for your account, and check what the region column says.

If that checks out, make sure the (correct) env var is set, and check that that's in fact what ends up in your config file (doing die(App::env('S3_REGION')) inside the config file is the quick and dirty way to do that).

If both of those seems ok, let me know and I'll look into if something in AWS has changed recently that I need to look at. A quick test shows that the S3 integration still works in my test environment, so it's either a config- or environment-specific thing.

pimago commented 1 year ago

Hi André, yes that's the bucket region. In the bucket properties it says: Bucket overview AWS Region Europe (Frankfurt) eu-central-1

The env var is correct it returns eu-central-1. Craft itself is handling the S3 upload fine. Probably I am overlooking something else.

aelvan commented 1 year ago

Ok, I'll try to set up a new bucket based on Andrew´s setup and see if I can reproduce.

aelvan commented 1 year ago

Hi,

I've tested again, setting up a brand new AWS setup using Andrew's tutorial, and everything works as expected.

I've tried provoking the error you're seeing, and the only way to get that exact error, is if region is an empty string, ''. If it has any value at all, or null, you'll get other errors. So I'll have to conclude that the env var is not working, or something happens to that value on the way through Imager's code, which seems unlikely. Have you tried hardcoding the value for region as a test, ie 'region' => 'eu-central-1'?

pimago commented 1 year ago

I did try that. Somehow the error log for the missing region is gone in general. But I am still not seeing any image. Maybe there is something with my S3 setting. When I open the broken image I get an access denied xml file.

pimago commented 1 year ago

I checked the debug toolbar. The region error is back. I don't know why it was gone yesterday. The region is still hardcoded. But there is also another error:

An error occured when trying to upload file "/var/www/html/web/imager/images/3028/dealerofdecaythumb-Kopie-2_398ca7b8debe49bfbe7d47514c01e3d7.webp" to external storage "aws". The transformed file has been deleted.