Skip to content

chore: fix missing node_modules in lambda zip v2#248

Merged
ava-silver merged 8 commits into
mainfrom
ava.silver/chore/fix-missing-node_modules-in-lambda-zip-v2
May 6, 2026
Merged

chore: fix missing node_modules in lambda zip v2#248
ava-silver merged 8 commits into
mainfrom
ava.silver/chore/fix-missing-node_modules-in-lambda-zip-v2

Conversation

@ava-silver
Copy link
Copy Markdown
Contributor

@ava-silver ava-silver commented May 6, 2026

What does this PR do?

Fixes the macro Lambda zip missing node_modules/ (issue #242). Two changes:

  1. Inlines the install step into build. yarn berry does NOT auto-run arbitrary pre/post hooks (only well-known lifecycle scripts like prepare, postinstall). PR [SVLS-8827] upgrade to yarn berry and add npm minimal age gate #238's yarn berry migration silently broke the postbuild hook so the install step never ran in any environment. New build script: tsc && cp package.json dist/package.json && npm install --omit=dev --prefix dist.

  2. Replaces the false-positive CI check with one that actually inspects the zip. The previous check (cd dist && node -e "require('./src/index.js')") always passed because Node's module resolution walked up from dist/ into serverless/node_modules/ (populated by yarn install) and found loglevel there — even when dist/node_modules/ was empty. The new check zips dist/, extracts to a clean /tmp/ directory (no parent node_modules/ to fall back to), and runs the require there.

Motivation

v0.27.1 still ships a broken Lambda. PR #244 changed the postbuild script and added a "verify Lambda bundle" step that both passed CI and shipped — but neither actually did anything: the postbuild was dead code under yarn berry, and the verify step was finding deps in the parent's node_modules. See #242 and the ZD ticket for customer reports.

Testing Guidelines

  • cd serverless && rm -rf dist && yarn build → confirm dist/node_modules/loglevel and dist/node_modules/@aws-sdk/ exist
  • Zip + extract + require sanity check (what the new CI step does):
    cd serverless/dist && zip -q -r /tmp/test.zip ./
    rm -rf /tmp/verify && mkdir /tmp/verify && unzip -q /tmp/test.zip -d /tmp/verify
    cd /tmp/verify && node -e "require('./src/index.js')"
    

Proof

CI:

End-to-end against real AWS + Datadog (US1, sandbox account 425362996713):

  • Built the fixed zip locally → 9.1 MB / 4274 files (vs. broken 128 KB / 148 files in v0.27.1).
  • Uploaded to S3 and deployed the macro stack ava-silver-macro-fix242 in us-east-1no Cannot find module 'loglevel' failure on the macro Lambda's cold start (this is the regression we fixed).
  • Deployed a sample SAM stack ava-fix242-hello-stack with Transform: DatadogServerless. The macro instrumented the function as expected: Datadog-Node22 layer v132 + Datadog-Extension layer v92, handler rewritten to /opt/nodejs/node_modules/datadog-lambda-js/handler.handler, all DD_* env vars set.
  • Invoked ava-fix242-hello 20+ times. Lambda logs show the extension running cleanly and successfully flushing traces: DD_EXTENSION | DEBUG | Request succeeded status=202 Accepted for https://trace.agent.datadoghq.com/api/v0.2/traces.
  • Datadog APM: traces for service:ava-fix242-test env:sandbox (last 1h). Sample trace IDs you can plug into https://ddserverless.datadoghq.com/apm/trace/<id> (US1 org corresponding to the API key used): 4986331605483463556, 6788063569943029167, 8662992718378330393.

Types of changes

  • Bug fix

Check all that apply

  • This PR's description is comprehensive

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.72%. Comparing base (49cd234) to head (b780b52).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #248   +/-   ##
=======================================
  Coverage   82.72%   82.72%           
=======================================
  Files          19       19           
  Lines         938      938           
  Branches      231      231           
=======================================
  Hits          776      776           
  Misses         91       91           
  Partials       71       71           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ava-silver ava-silver marked this pull request as ready for review May 6, 2026 18:25
@ava-silver ava-silver requested a review from a team as a code owner May 6, 2026 18:25
@ava-silver ava-silver requested a review from nina9753 May 6, 2026 18:25
@ava-silver ava-silver merged commit 4a10002 into main May 6, 2026
10 checks passed
@ava-silver ava-silver deleted the ava.silver/chore/fix-missing-node_modules-in-lambda-zip-v2 branch May 6, 2026 18:31
@ava-silver ava-silver mentioned this pull request May 6, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants