aws-s3
aws-s3 copied to clipboard
Rekognition returns a 400 if using an environment variable for Subfolder
Description
When you setup your Asset Volume in settings, if you are using an environment variable for the Subfolder field Rekognition will fail. If you replace the variable with the exact text it represents it will succeed.
Error:
error: "Error executing "DetectFaces" on "https://rekognition.us-east-1.amazonaws.com";
AWS HTTP error: Client error: POST https://rekognition.us-east-1.amazonaws.com resulted in a 400 Bad Request response:
{"__type":"InvalidS3ObjectException","Code":"InvalidS3ObjectException","Message":"Unable to get object metadata from S3. (truncated...)
InvalidS3ObjectException (client): Unable to get object metadata from S3. Check object key, region and/or access permissions. - {"__type":"InvalidS3ObjectException","Code":"InvalidS3ObjectException","Message":"Unable to get object metadata from S3. Check object key, region and/or access permissions."}"
Steps to reproduce
- Create a new Asset Volume under Settings > Assets > New Volume
- Give it a name and handle
- Give it a public URL
- Choose Amazon S3 for volume type
- I use Environment Variables for all the S3 specific values (using Manual). These do not throw any errors. This includes, the Key ID, Secret, Bucket, and Region
- For Subfolder, use $S3_SUBFOLDER_IMG. Ensure you have variables in your .env file. Mine are: S3_ACCESS_KEY_ID="OMITTED" S3_SECRET_ACCESS_KEY="OMITTED" S3_BUCKET="uschamber.com-assets-local" S3_REGION="us-east-1" S3_BASE_URL="https://s3.us-east-1.amazonaws.com/uschamber.com-assets-local/" S3_SUBFOLDER_IMG="mbloomfield/assets/images"
- Keep Toggle for adding the subfolder to the Base URL to
true - Make uploads Public also
true - Enable auto-set focal point.
- No other fields are set
- Attempt to upload an image to the volume (via Assets or through an entry with an asset field).
- Note that it does not work (error received above)
- Go back to settings, update Subfolder from $S3_SUBFOLDER_IMG to 'mbloomfield/assets/images'
- Attempt another upload.
- Note that it works
Video depicting issue
https://www.loom.com/share/d443b6f7b49342f3a89b0c70ad2f77fe
Additional info
- Craft version: 3.5.15.1
- PHP version: 7.1.26
- Database driver & version: MySQL 5.7.30
- Plugins & versions:
Amazon S3 | 1.2.11 Bulk Edit | 2.0.5 CP Field Inspect | 1.2.3 Default Dashboard | 1.0.8 Do It Yourself widget | 2.0.2 Embedded Assets | 2.4.3 Environment Label | 3.2.0 Expanded Singles | 1.1.3 Field Manager | 2.2.1 Freeform | 3.9.2 Mailgun | 1.4.3 Mix | 1.5.2 Navigation | 1.4.2 Neo | 2.8.14 oEmbed | 1.3.6 Read Time | 1.6.0 Redactor | 2.8.3 Redactor Custom Styles | 3.0.4 Redirect Manager | 1.1.1 SEOMate | 1.1.7 Super Table | 2.6.3 Tags | 1.0.7 Wordsmith | 3.3.0.1
IF you are also facing this issue, putting an alias in my general.php that references the environment variable solved it for me:
// config/general.php
'local' => [
...,
'aliases' => [
'@s3SubfolderImg' => getenv('S3_SUBFOLDER_IMG'),
],
],
Then just reference that alias instead of the environment variable.