aws-samples / image-optimization

Simple, performant and cost efficient solution for optimizing images using Amazon CloudFront, Amazon S3 and AWS Lambda
MIT No Attribution
174 stars 106 forks source link

Getting internal server error (502 Bad Gateway) #22

Closed colehorvitz closed 6 months ago

colehorvitz commented 7 months ago

Hello, I have deployed the solution as described by the tutorial. When I arrive at the part which says, " To verify that it is working properly, test the following optimized image URL https:// YOURDISTRIBUTION.cloudfront.net/images/rio/1.jpeg?format=auto&width=300", I go to the URL and receive a 502 server error (bad gateway). The screen says "internal server error". Any ideas?

The X-Amz-Cf-Id is 59DzRpe8853TUlsoAlUELQiFMzgGS1dPLRgsDw_9bQHQ_2JcGXdt6A==

achrafsouk commented 7 months ago

can you please share the error in the Lambda log?

colehorvitz commented 7 months ago

ah, seems like it's the same issue mentioned here https://github.com/aws-samples/image-optimization/issues/7#issuecomment-1683602984

"Error: Could not load the \"sharp\" module using the linux-x64 runtime"

But I am running npm run build :/

achrafsouk commented 7 months ago

I suspect that this is because the machine your running the build on is different from the Lambda's.

What is the machine characteristics you are running the build on?

polo4096 commented 7 months ago

Hey ! I also had some troubles making it work yesterday, I was installing sharp from MacOS ARM chip and couldn't make it work for x64 arch, so instead I used a lambda layer for sharp library and it worked out of the box. @achrafsouk It seems that the prebuild command is somehow deprecated for M1/M2 users

achrafsouk commented 7 months ago

yeah better build it on an EC2 instance with similar CPU architecture as Lambda. I'll note it in the readme.

piotrekwitkowski commented 6 months ago

There is currently an open issue in npm that prevents you from installing platform-specific dependencies (like sharp for x64 arch on Mac with ARM chips): https://github.com/npm/cli/issues/4828 - please upvote the issue if you are experiencing similar problems.

ClementCardonnel commented 1 month ago

Hello, I've encountered this error too… I'm a beginner regarding AWS and I don't know how I could do a build on an EC2 instance… Could someone point me in the right direction?

EDIT: This answer was helpful: https://github.com/aws-samples/image-optimization/issues/35#issuecomment-2026313394