sladg / nextjs-lambda

Lambda deployments for Nextjs12 & Nextjs13 (standalone). Easy CLI commands to get your standalone Next output to run in AWS Lambda (not @Edge)! Uses CDK in behind and produces code zips importable to Terraform, Serverless, Azure, etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bundle image handler with Sharp

sladg opened this issue · comments

commented

Existing implementation was error prone, creating unnecessary complexity and layers.
There needs to be easier way how to bundle image handler and include Sharp for Lambda as well.

Currently using Squoosh for image handling, which is not recommended for production use with Vercel.

I'd be interested in how you're bundling sharp into the lambda Function/NodejsFunction. Sharp spawns a child process and executes the sharp binary, it might not be possible to bundle the sharp code into the function.

commented

@khuezy Lambda on it's own does not care about child processes, the problem is typical in binaries that needs to be compiled specifically for Lambda's environment.
Also, Next uses rather shitty implementation for figuring out where sharp is, so that might also be pain.

Will send code once done :)

commented

Next's built-in image handler will be replaced by custom solution as it ultimately sucks.
Bundling is overly complicated, passing binaries does not work as expected, hacking all around is needed.

Related to #64

Will be optionally secured by providing allowed image sources.
Expected in version 4 (in couple of days).

commented

As of v4, image optimizer was moved to separate package.
Changes: release/v3.22.0...v4.0.0
New optimizer: https://github.com/sladg/imaginex-lambda