title: Lambda@Edge Gives 502 only for SOME images
body: <p>What we do is take a request for an image like "media/catalog/product/3/0/30123/768x/lorem.jpg", then we use the original image located at "media/catalog/product/3/0/30123.jpg", resize it to 768px and webp if the browser supports that and then return the new image (if not already cached).</p>
  
  <p>If you request: wysiwyg/lorem.jpg it will try to create a webp in maximum 1920 pixels (no enlargement).</p>
  
  <p>This seems to work perfectly fine up to &lt;= 1420 pixels wide image. However above that we only get <code>HTTP 502: The Lambda function returned invalid json: The json output is not parsable.</code></p>
  
  <p>There is a similar issue on SO that relates to GZIP, however as I understand you shouldn't really GZIP images: <a href="https://webmasters.stackexchange.com/questions/8382/gzipped-images-is-it-worth/57590#57590">https://webmasters.stackexchange.com/questions/8382/gzipped-images-is-it-worth/57590#57590</a></p>
  
  <p>But it's possible that the original image was uploaded to S3 GZIPPED already. But the gzip might be miss-leading because why would it work for smaller images then? We have GZIP disabled in Cloudfront. </p>
  
  <p>I have given the Lamda@Edge Resize function maximum resources 3GB memory and timeout of 30 seconds.. Is this not sufficient for larger images?</p>
  
  <p>I have deleted the already generated images, invalidated Cloudfront but it still behaves the same..</p>
  
  <p><strong>EDIT: UPDATE</strong>:</p>
  
  <p>I simply tried a different image and then it works fine.. I have no idea why and how I should solve the broken image then... I guess Cloudfront has cached the 502 now.. I have invalidated using just "*" but didn't help.. Both original files are jpg.</p>
  
  <p>The original source image for the working one is 6.1 MB and non working is 6.7 MB if that matters.</p>
  
  <p>They have these limits:
  <a href="https://docs.aws.amazon.com/lambda/latest/dg/limits.html" rel="noreferrer">https://docs.aws.amazon.com/lambda/latest/dg/limits.html</a></p>
  
  <p>The response.body is about 512 MB when it stops working.</p>