{"library":"serverless-middleware","title":"serverless-middleware","description":"Serverless Framework plugin (v3.4.0) enabling middleware chaining directly in serverless.yaml for AWS Lambda functions. Allows defining pre/post handlers, error catches, and execution termination via context.end(). Supports Node.js 14+ (12x–22x) and ES6 modules since v3.2.0. Differentiator: no code changes required—all wiring in YAML; supports mixed then/catch chains and TypeScript with webpack workaround. Released semi-annually, breaking changes limited to runtime/Serverless major bumps.","language":"javascript","status":"active","last_verified":"Sat Apr 25","install":{"commands":["npm install serverless-middleware"],"cli":null},"imports":["plugins:\n  - serverless-middleware","// handler.js\nexport const authenticate = async (event, context) => { ... };","import serverlessMiddleware from 'serverless-middleware';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"npm install serverless-middleware --save-dev\n# serverless.yaml\nplugins:\n  - serverless-middleware\nprovider:\n  name: aws\n  runtime: nodejs22.x\nfunctions:\n  myFunction:\n    handler: handler.main\n    middleware:\n      - auth.authenticate\n      - then: handler.main\n      - catch: handler.error\n\n# handler.js\nexport const authenticate = async (event, context) => {\n  if (!event.headers.Authorization) {\n    throw new Error('Unauthorized');\n  }\n  return { ...event, auth: true };\n};\nexport const main = async (event) => ({\n  statusCode: 200,\n  body: JSON.stringify({ message: 'Hello' }),\n});\nexport const error = async (error, event, context) => ({\n  statusCode: 500,\n  body: JSON.stringify({ error: error.message }),\n});","lang":"javascript","description":"Install plugin, configure middleware chains in YAML, and define async handlers. Shows auth, main, and error handlers.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}