Lambda handlers can become hard to understand & change. The reason is that the handler logic can complect multiple orthogonal concepts:
- the logic for parsing & validating input
- the logic for getting configurations, such as from AWS Parameter Store or AWS Secrets Manager
- the logic for getting db connection
- the logic for serializing the output & errors
Having multiple intertwined concepts makes things hard: we first needed to understand this complex thing before we could improve it.
This applies for new projects/lambdas as well.
These braids can be elegantly decomplected using a middleware, such as [middy][middy].
With middy, you can transform the handler's boilerplate into reusable & [[Decomplecting intertwined things|simple lego bricks]].
The handler became simpler & easier to understand
#typescript #serverless
[middy]: https://github.com/middyjs/middy