A middleware for the Middy framework (v2.5.3+ peer dependency) that provides global access to current AWS Lambda invocation event and context from anywhere in your code, eliminating the need to pass them as arguments through function calls. This is a small, focused utility with no active development since v1.0.0 (2022). Key differentiator: it uses async hooks (presumably) to store the invocation context, enabling access from deeply nested modules. Similar libraries include @middy/core's built-in context sharing, but this offers a simpler getter pattern. Only one known release (v1.0.0) with no changelog or updates.
npm install middy-invocationVerified import paths — ran on the pinned version, not inferred.
Shows middleware registration and how to access event/context via getter functions in a handler.
Ensure usage is always inside a handler invocation, not at module load time.
Pin @middy/core to ^2.5.3 or migrate to a maintained alternative.
Use require() instead of import, or use dynamic import() if your runtime supports it.
Capture event/context immediately in the handler and pass explicitly, or use AsyncLocalStorage for isolation.
Create a local .d.ts file or use `any` typecasting.
Correct: middy(handler).use(invocation())
Use `const { event } = require('middy-invocation'); const evt = event();` inside the handler.Run `npm install @middy/core@^2.5.3 middy-invocation`