Skip to content

feat(aws): Create unified lambda layer for ESM and CJS - #17012

Merged
andreiborza merged 6 commits into
developfrom
ms/esm-lambda-layer
Jul 18, 2025
Merged

feat(aws): Create unified lambda layer for ESM and CJS#17012
andreiborza merged 6 commits into
developfrom
ms/esm-lambda-layer

Conversation

@msonnb

@msonnbmsonnb commented Jul 15, 2025

Copy link
Copy Markdown
Member

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

Comment threadpackages/aws-serverless/scripts/buildLambdaLayer.ts
Comment threadpackages/aws-serverless/scripts/buildLambdaLayer.ts
Comment threadpackages/aws-serverless/scripts/buildLambdaLayer.ts Outdated
@msonnbmsonnb self-assigned this Jul 15, 2025
@msonnb
msonnbforce-pushed the ms/esm-lambda-layer branch 3 times, most recently from 88d24b0 to 5a9af39CompareJuly 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 andreiborzaJuly 18, 2025 07:40
cursor[bot]

This comment was marked as outdated.

@andreiborzaandreiborza left a comment

Copy link
Copy Markdown
Member

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!

Comment threaddev-packages/e2e-tests/test-applications/aws-lambda-layer-esm/package.json Outdated
Comment threadpackages/aws-serverless/scripts/buildLambdaLayer.ts Outdated
Comment threadpackages/aws-serverless/scripts/buildLambdaLayer.ts
Comment threadpackages/aws-serverless/scripts/buildLambdaLayer.ts
Comment threadpackages/aws-serverless/scripts/buildLambdaLayer.ts Outdated
@msonnb
msonnbforce-pushed the ms/esm-lambda-layer branch from 5a9af39 to 04a8f62CompareJuly 18, 2025 13:10
cursor[bot]

This comment was marked as outdated.

@andreiborzaandreiborza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🚀

@cursorcursorBot left a comment

Copy link
Copy Markdown

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

asyncfunctionpruneNodeModules(): Promise<void>{
constentrypoints=[
'./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 }=awaitnodeFileTrace(entrypoints);
constallFiles=getAllFiles('./build/aws/dist-serverless/nodejs/node_modules');
constfilesToDelete=allFiles.filter(file=>!fileList.has(file));

Fix in CursorFix in Web


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

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants

@msonnb@mydea@andreiborza