fix: correct sharp cross-platform bundling for image handler Lambda#647
Open
ButterflyJuicer0 wants to merge 1 commit into
Open
fix: correct sharp cross-platform bundling for image handler Lambda#647ButterflyJuicer0 wants to merge 1 commit into
ButterflyJuicer0 wants to merge 1 commit into
Conversation
The afterBundling hook produced a darwin sharp binary that fails to load
on the linux-x64 Lambda runtime ("Could not load the sharp module"),
returning 502 for every request when synthesized on macOS.
Three compounding issues are fixed:
- The `cd` and `npm install` were separate array elements; CDK runs each
in its own shell, so the directory change never applied to the install.
They are now a single chained command.
- Only `node_modules/sharp` was removed, but sharp 0.33+ ships native
binaries under `@img/sharp-<platform>`, so the host binary survived.
`node_modules/@img` is now removed too.
- The copied package-lock.json pinned darwin deps and overrode the
--os/--cpu flags. The lock is now removed and --include=optional is
added so npm 11 actually pulls the linux-x64 @img package.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #646
Summary
The
afterBundlingcommand hook for the image handler Lambda produced a macOS (darwin-arm64) sharp binary that fails to load on the linux-x64 Lambda runtime, causingCould not load the "sharp" moduleand HTTP 502 for every request when synthesized on macOS.This PR fixes three compounding issues in a single hook command:
cdwas split from the install. The hook returned two array elements; CDK runs each in its own shell, socd ${outputDir}never applied to thenpm install. They are now chained into one command.@img/binaries were not removed. sharp 0.33+ ships native binaries under@img/sharp-<platform>, so removing onlynode_modules/sharpleft the host darwin binary.node_modules/@imgis now removed too.package-lock.jsonoverrode the--os/--cpuflags. It is now removed, and--include=optionalis added so npm 11 actually pulls the linux-x64@imgpackage.修复说明
afterBundling钩子打进 Lambda 的是 macOS 版 sharp 二进制,在 linux-x64 运行时加载失败,导致每个请求 502。本 PR 在单条钩子命令里修复三个叠加问题:cd与 install 合并为一条命令;额外删除@img/(sharp 0.33+ 的原生二进制目录);删除锁定 darwin 的package-lock.json并加--include=optional以适配 npm 11。Test plan
cdk synthon macOS now produces@img/sharp-linux-x64(verified the staged asset).v7-Stackto us-east-1; image handler Lambda loads sharp successfully.