Registry / aws / middy-invocation

middy-invocation

JSON →
library1.0.0jsnpmunverified

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-invocation
INSTALL
IMPORT
SIG · MIDDY-INVOCATION
M
middy-invocation
awsjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

invocation
const invocation = require('middy-invocation');
import invocation from 'middy-invocation';
CJS default export; package does not ship ESM types or exports.
event
const { event } = require('middy-invocation'); const evt = event();
import { event } from 'middy-invocation'; const evt = event;
Named export is a function that returns the current event; do not destructure if you need to call later.
context
const { context } = require('middy-invocation'); const ctx = context();
const context = require('middy-invocation').context; const ctx = context;
Same as event: context is a function, not the actual context object.

Shows middleware registration and how to access event/context via getter functions in a handler.

const middy = require('@middy/core'); const invocation = require('middy-invocation'); const baseHandler = async (event, context) => { // Access event and context from anywhere const { event: getEvent, context: getContext } = require('middy-invocation'); const evt = getEvent(); const ctx = getContext(); console.log('Request ID:', ctx.awsRequestId); return { statusCode: 200, body: JSON.stringify(evt) }; }; module.exports.handler = middy(baseHandler).use(invocation());
Debug
Known issues
gotchaThe event and context functions must be called after the middleware has run (i.e., only within the handler function or its async chain).
fix
Ensure usage is always inside a handler invocation, not at module load time.
affects: >=0.0.0
deprecatedPackage requires @middy/core ^2.5.3 peer dependency; no support for @middy/core v3+.
fix
Pin @middy/core to ^2.5.3 or migrate to a maintained alternative.
affects: >=1.0.0
breakingOnly CJS exports; no ES module support.
fix
Use require() instead of import, or use dynamic import() if your runtime supports it.
affects: >=0.0.0
gotchaIf multiple invocations run concurrently (e.g., with context reuse in warm containers), the stored event/context may be overwritten by a later invocation.
fix
Capture event/context immediately in the handler and pass explicitly, or use AsyncLocalStorage for isolation.
affects: >=0.0.0
gotchaNo TypeScript types are provided; using the package in TypeScript requires manual type declarations or @types/middy-invocation (which does not exist).
fix
Create a local .d.ts file or use `any` typecasting.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: invocation is not a function
Trying to use `invocation` as a function after import, but it's already a middleware factory.
fix
Correct: middy(handler).use(invocation())
ReferenceError: Cannot access 'event' before initialization
Attempting to destructure `event` before calling the function, or using it outside of handler scope.
fix
Use `const { event } = require('middy-invocation'); const evt = event();` inside the handler.
Cannot find module 'middy-invocation'
Package not installed or peer dependency @middy/core missing.
fix
Run `npm install @middy/core@^2.5.3 middy-invocation`
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@middy/corerequiredPeer dependency required for middleware registration; must be >=2.0.0
Agent activity
10 hits · last 30 days
node
10
Resources
middy-invocation — npm install middy-invocation · libregistry