1
votes

I followed this blog https://aws.amazon.com/blogs/compute/resize-images-on-the-fly-with-amazon-s3-aws-lambda-and-amazon-api-gateway/

and this repo https://github.com/awslabs/serverless-image-resizing

To be able to resize images on AWS S3 on the fly. The bucket is created successfully. Whenever I upload image to the bucket, I can resize it from the url as indicated in the blog, everything works fine.

The problem is when an image is uploaded from the code (Ruby on Rails using paperclip), then the image can be accessed normally, however when trying with resizing url (e.g. /100x200/photo.png) I receive this in the browser as json response

{
"message": "Internal server error"
}

The response headers are: 

Request URL:<url>
Request Method:GET
Status Code:502 
Remote Address:<IP>
Referrer Policy:no-referrer-when-downgrade
Response Headers
content-length:36
content-type:application/json
date:Thu, 23 Nov 2017 09:59:24 GMT
status:502
via:1.1 <hash>.cloudfront.net (CloudFront)
x-amz-cf-id:<id>
x-amzn-requestid:<id>
x-cache:Error from cloudfront
Request Headers
:authority:<url>
:method:GET
:path:/prod?key=<path/to/photo>
:scheme:https
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
accept-encoding:gzip, deflate, br
accept-language:en-US,en;q=0.9,de;q=0.8,ar;q=0.7
cache-control:max-age=0
upgrade-insecure-requests:1
user-agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36
Query String Parameters
view source
view URL encoded
key:<path/to/photo>

The very strange thing is that, after the error occurs, when I upload the same image manually again under any place in the bucket then I try again using the original resize url, not the new uploaded image url that caused a problem, it works normally and I can resize to any size !

So it seems like uploading manually triggers something related to this very image data ? I have no clue!

1

1 Answers

1
votes

The error here that you put the required size before file name directly, you should put it before the whole file path.

Make sure that you follow this pattern:

http://$BucketWebsiteHost/$size/$imagePath

Example:

http://mybucketname.s3-website.mybucketregion.amazonaws.com/60x50/photos/attachments/000/002/002/original/image.jpg