Closed sslotsky closed 1 year ago
Also worth noting: when I try this on our staging environment it's the same results, but with one minor difference: the stack trace when I execute the transfer-order-shipped-handler
doesn't even appear to show the wrapped handler! No mention of .build/.middleware/
in that stack at all. But the HTTP API works with no issue!
{
"errorType": "Error",
"errorMessage": "No matching bindings found for serviceIdentifier: TransferOrderShippedHandler",
"trace": [
"Error: No matching bindings found for serviceIdentifier: TransferOrderShippedHandler",
" at _validateActiveBindingCount (/var/task/node_modules/inversify/lib/planning/planner.js:82:23)",
" at _getActiveBindings (/var/task/node_modules/inversify/lib/planning/planner.js:68:5)",
" at _createSubRequests (/var/task/node_modules/inversify/lib/planning/planner.js:103:26)",
" at plan (/var/task/node_modules/inversify/lib/planning/planner.js:154:9)",
" at /var/task/node_modules/inversify/lib/container/container.js:620:46",
" at Container._get (/var/task/node_modules/inversify/lib/container/container.js:590:38)",
" at Container._getButThrowIfAsync (/var/task/node_modules/inversify/lib/container/container.js:593:27)",
" at Container.get (/var/task/node_modules/inversify/lib/container/container.js:374:21)",
" at Object.<anonymous> (/var/task/src/transfer/queue/transfer-order-shipped-handler/TransferOrderShippedHandlerLambda.js:7:135)",
" at Module._compile (node:internal/modules/cjs/loader:1105:14)",
" at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)",
" at Module.load (node:internal/modules/cjs/loader:981:32)",
" at Function.Module._load (node:internal/modules/cjs/loader:822:12)",
" at Module.require (node:internal/modules/cjs/loader:1005:19)",
" at Module.Hook.Module.require (/opt/nodejs/node_modules/dd-trace/packages/dd-trace/src/ritm.js:72:33)",
" at require (node:internal/modules/cjs/helpers:102:18)"
]```
On coming back from the weekend I'm entirely sure that this is my fault. The TransferOrderShippedHandler
that I'm trying to wrap calls iocContainer.get()
on import, and the handler that's generated by this plugin obviously needs to import the handler at the very beginning, so we therefore try to access the container before the middleware can even be invoked. Will have to think on that.
I have configured both
pre
andpos
middleware handlers which work fine when invoking the function that hosts our HTTP API. But when I invoke any other function, it appears the middleware does not run.Plugins are configured like this:
Middleware is configured universally:
The initialize function loads async bindings into my IOC container, and teardown unbinds them. The function that behaves correctly is declared like this:
When I add
console.log
statements in myinitialize
andteardown
handlers, I can see the console output when I make a request with Postman. But it does not work correctly when I useaws lambda invoke
to test this other function:When I invoke this function, I know that
initialize
does not run because. Partly because I don't see the console output, but also because the exception that gets thrown by the handler indicates that my IOC container was not initialized. Take a look at the bottom line of that stack trace:That line shows that the new handler that was generated by
serverless-middleware
is the one that's being invoked. The contents of that file look exactly like you'd expect them to:They chain the original handler together with the middleware handlers, in the exact same way that they do in the handler defined by
.build/.middleware/transfer-api-dev.js
. So it is extremely puzzling to me that theinitialize
function is not getting invoked.