{"id":18556,"library":"middy-invocation","title":"Middy Invocation Middleware","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/serkan-ozal/middy-invocation","tags":["javascript","middy","serverless","aws","lambda"],"install":[{"cmd":"npm install middy-invocation","lang":"bash","label":"npm"},{"cmd":"yarn add middy-invocation","lang":"bash","label":"yarn"},{"cmd":"pnpm add middy-invocation","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for middleware registration; must be >=2.0.0","package":"@middy/core","optional":false}],"imports":[{"note":"CJS default export; package does not ship ESM types or exports.","wrong":"import invocation from 'middy-invocation';","symbol":"invocation","correct":"const invocation = require('middy-invocation');"},{"note":"Named export is a function that returns the current event; do not destructure if you need to call later.","wrong":"import { event } from 'middy-invocation'; const evt = event;","symbol":"event","correct":"const { event } = require('middy-invocation'); const evt = event();"},{"note":"Same as event: context is a function, not the actual context object.","wrong":"const context = require('middy-invocation').context; const ctx = context;","symbol":"context","correct":"const { context } = require('middy-invocation'); const ctx = context();"}],"quickstart":{"code":"const middy = require('@middy/core');\nconst invocation = require('middy-invocation');\n\nconst baseHandler = async (event, context) => {\n  // Access event and context from anywhere\n  const { event: getEvent, context: getContext } = require('middy-invocation');\n  const evt = getEvent();\n  const ctx = getContext();\n  console.log('Request ID:', ctx.awsRequestId);\n  return { statusCode: 200, body: JSON.stringify(evt) };\n};\n\nmodule.exports.handler = middy(baseHandler).use(invocation());","lang":"javascript","description":"Shows middleware registration and how to access event/context via getter functions in a handler."},"warnings":[{"fix":"Ensure usage is always inside a handler invocation, not at module load time.","message":"The event and context functions must be called after the middleware has run (i.e., only within the handler function or its async chain).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Pin @middy/core to ^2.5.3 or migrate to a maintained alternative.","message":"Package requires @middy/core ^2.5.3 peer dependency; no support for @middy/core v3+.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use require() instead of import, or use dynamic import() if your runtime supports it.","message":"Only CJS exports; no ES module support.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Capture event/context immediately in the handler and pass explicitly, or use AsyncLocalStorage for isolation.","message":"If multiple invocations run concurrently (e.g., with context reuse in warm containers), the stored event/context may be overwritten by a later invocation.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Create a local .d.ts file or use `any` typecasting.","message":"No TypeScript types are provided; using the package in TypeScript requires manual type declarations or @types/middy-invocation (which does not exist).","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Correct: middy(handler).use(invocation())","cause":"Trying to use `invocation` as a function after import, but it's already a middleware factory.","error":"TypeError: invocation is not a function"},{"fix":"Use `const { event } = require('middy-invocation'); const evt = event();` inside the handler.","cause":"Attempting to destructure `event` before calling the function, or using it outside of handler scope.","error":"ReferenceError: Cannot access 'event' before initialization"},{"fix":"Run `npm install @middy/core@^2.5.3 middy-invocation`","cause":"Package not installed or peer dependency @middy/core missing.","error":"Cannot find module 'middy-invocation'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}