-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(aws): Create unified lambda layer for ESM and CJS #17012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
88d24b0
to
5a9af39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, just a few minor comments. I think we can give this a spin!
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/package.json
Outdated
Show resolved
Hide resolved
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/package.json
Show resolved
Hide resolved
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/start-event-proxy.mjs
Outdated
Show resolved
Hide resolved
dev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/tests/basic.test.ts
Outdated
Show resolved
Hide resolved
feat(aws): Create unified lambda layer for ESM and CJS
5a9af39
to
04a8f62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Inconsistent Path Handling Causes Pruning Failures
The node_modules
pruning logic fails due to inconsistent path formatting. Paths from @vercel/nft
(based on entrypoints
with ./
prefix) and paths from getAllFiles
(relative to process.cwd()
) do not consistently match, potentially due to leading ./
differences and platform-specific path separators. This causes the file filtering to fail, leading to incorrect pruning (e.g., deleting all files or preserving/deleting the wrong ones).
Additionally, the nodeFileTrace
call lacks error handling; if any hardcoded entrypoint files are missing, it will crash the build process.
packages/aws-serverless/scripts/buildLambdaLayer.ts#L66-L78
sentry-javascript/packages/aws-serverless/scripts/buildLambdaLayer.ts
Lines 66 to 78 in 4ad4e49
async function pruneNodeModules(): Promise<void> { | |
const entrypoints = [ | |
'./build/aws/dist-serverless/nodejs/node_modules/@sentry/aws-serverless/build/npm/esm/index.js', | |
'./build/aws/dist-serverless/nodejs/node_modules/@sentry/aws-serverless/build/npm/cjs/index.js', | |
'./build/aws/dist-serverless/nodejs/node_modules/@sentry/aws-serverless/build/npm/cjs/awslambda-auto.js', | |
'./build/aws/dist-serverless/nodejs/node_modules/@sentry/aws-serverless/build/npm/esm/awslambda-auto.js', | |
]; | |
const { fileList } = await nodeFileTrace(entrypoints); | |
const allFiles = getAllFiles('./build/aws/dist-serverless/nodejs/node_modules'); | |
const filesToDelete = allFiles.filter(file => !fileList.has(file)); |
Was this report helpful? Give feedback by reacting with 👍 or 👎
This introduces a new AWS lambda layer that supports both ESM and CJS. Instead of bundling the whole SDK, we install the local NPM package and then prune all not strictly necessary files from
node_modules
by using@vercel/nft
to keep the layer size as small as possible.closes #16876
closes #16883
closes #16886
closes #16879