Comments (14)
Also, @vladgolubev, I really like the idea of having scoped package as babel. we might have the following approach:
const middy = require('@middy/middy') // or '@middy/core' or simply 'middy'
const doNotWaitForEmptyEventLoop = require('@middy/doNotWaitForEmptyEventLoop')
from middy.
I was thinking about this the other day as well.
We want to include only the code required for a given lambda to run.
We can optimize in two places
- at runtime like @NPCRUS suggests
- the actual project size in
node_modules
. The size of zip effects perf as well, so even if you only include 1 middleware, the s3 zip still needs to load and keeping things lean is a "best practice" as it were
You can solve this in userland with webpack/rollup
but I think we can also help users not shoot themselves in the foot forcing this with middleware published as separate packages
We could have middleware published as separate packages with a tool like https://lernajs.io/ (or the new packaging tool the lerna creator is close to finishing)
So a user would install the lean core and only the middleware they need.
npm install middy # lean core
npm install middy-validator
npm install middy-json-body-parser
etc
This would keep the zip as tiny as possible.
The repo can stay a monorepo, it's just a change to how the middleware would get published to npm via lerna
from middy.
Agree with @DavidWells 👍
This is a perfect case for setup much like Babel has. One monorepo and complementary packages under @babel
npm org scope.
from middy.
I've done some research.
Looks like validator
(especially ajv
library) middleware loads about 140ms, which may be deadly amount of time for some services. And anyway since amount of prebuild middlewares is growing i think that it's not a good a good approach to load all of them. What I think will be possible to do here is get middlewares in such way
const validator = require('middy/middlewares').validator()
This will save execution time by not loading any other middlewares and still pretty handy and comfortable way to get middleware.
What do you think?
@lmammino
from middy.
Very good points from @NPCRUS and @DavidWells. The current architecture (and examples) are definitely helpful in terms of performance when using the bundled middlewares.
I like the options of using a mono-repo approach and separate the middlewares from the main core, so this might be something to consider for the near future, maybe targeting the first stable 1.0.0 release.
At the moment there's a very easy fix anyway, you can import middlewares directly as follows:
// imports only one middleware (doNotWaitForEmptyEventLoop)
const doNotWaitForEmptyEventLoop = require('middy/src/middlewares/doNotWaitForEmptyEventLoop')
This should do, until we figure out how to switch to a mono-repo approach.
Comments/thoughts?
from middy.
Hello @kevinrambaud 😉
For the moment I would suggest to use the approach mentioned above to avoid to load all the middlewares (and their dependencies) at once:
const doNotWaitForEmptyEventLoop = require('middy/src/middlewares/doNotWaitForEmptyEventLoop')
Moving towards a more stable 1.0.0
(yet to be planned), we will probably move towards a mono-repo approach where no middleware is bundled with the core and you have to install/require each and every one of them separately (similar to express or fastify).
from middy.
@lmammino Will do 👍
from middy.
Hey @lmammino any update about the approach you guys would prefer ?
from middy.
if you need any help, I would highly be interested to contribute 😁
from middy.
Definitely, all help is appreciated. I'll try to lay out a roadmap for 1.0.0, meanwhile, being an open source project, every area you feel needs an improvement, is probably something that deserves a PR or a discussion, so feel free to make your own suggestions 😉
from middy.
It'd be prudent to update your documentation to include this workaround.
from middy.
Hello @karlbateman, would you like to submit a PR for that?
from middy.
Awesome, i look forward to seeing your PR :)
from middy.
Closing, v1-beta is now out with mono-repo support.
from middy.
Related Issues (20)
- Not able to invoke the http-router routes from post-man using serverless-offiline HOT 4
- ERR_PACKAGE_PATH_NOT_EXPORTED error HOT 1
- index.d.ts still allows callback based handlers.
- dead links on getting started page HOT 1
- [middy/core] get event input in timeoutEarlyResponse parameter HOT 1
- Throws an error Error [ERR_PACKAGE_PATH_NOT_EXPORTED] HOT 1
- Restrict types to `APIGatewayProxyResultV2` or `APIGatewayProxyResult` HOT 2
- TypeScript compile error in @middy/core 5.2.4 HOT 7
- Lambda throwing `Failed to resolve internal values` in secretsManagerMiddlewareBefore HOT 3
- Simple lib import fails with both `tsx` and `ts-node` HOT 2
- LLRT Support
- TypeScript error when using `S3Handler` type HOT 3
- middy 5.2.5 isn't available on npm HOT 1
- Please give more descriptive error when throwing "Failed to resolve internal values" in secrets-manager module HOT 2
- middy/http-cors disable defaults and don't add headers HOT 1
- Streamified response with empty body ignores other response attributes HOT 3
- `http-error-handler` to support Problem Details (RFC 9457) HOT 1
- http-error-handler : set custom test to return error instead of `statusCode` HOT 2
- http-error-handler: guidance/bug on using lambda-authorizer with v5 HOT 1
- error-logger: Call implementation function with await prefix HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from middy.