Skip to content

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

Merged
merged 6 commits into from
Jul 18, 2025

Conversation

msonnb
Copy link
Member

@msonnb msonnb commented Jul 15, 2025

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

@msonnb msonnb self-assigned this Jul 15, 2025
@msonnb msonnb force-pushed the ms/esm-lambda-layer branch 3 times, most recently from 88d24b0 to 5a9af39 Compare July 18, 2025 07:37
@msonnb msonnb marked this pull request as ready for review July 18, 2025 07:37
@msonnb msonnb requested a review from andreiborza July 18, 2025 07:40
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@andreiborza andreiborza left a 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!

@msonnb msonnb force-pushed the ms/esm-lambda-layer branch from 5a9af39 to 04a8f62 Compare July 18, 2025 13:10
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link

@cursor cursor bot left a 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

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));

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@andreiborza andreiborza merged commit 5eb036f into develop Jul 18, 2025
651 of 663 checks passed
@andreiborza andreiborza deleted the ms/esm-lambda-layer branch July 18, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants