# Shared pre / post function code

**URL:** <https://forum.serverless.com/t/shared-pre-post-function-code/7710>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [March 18, 2019, 5:44am UTC](https://forum.serverless.com/t/shared-pre-post-function-code/7710 "2019-03-18T05:44:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thrixton](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/thrixton/32/2603_2.png) [@thrixton](https://forum.serverless.com/u/thrixton)\
**Post date:** [March 18, 2019, 5:44am UTC](https://forum.serverless.com/t/shared-pre-post-function-code/7710/1 "2019-03-18T05:44:24Z")

</div>

As the number of functions within an “app” increases, the need for shared code becomes greater, and the burden of maintaining the initialization of the shared code increases…  
To alleviate this, it would be good to be able to run a common function before (and potentially after) the function.  
Is there any way to accomplish this?

---

<div class="post-metadata">

**Author:** ![DavidWells](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/davidwells/32/201_2.png) [@DavidWells](https://forum.serverless.com/u/DavidWells)\
**Post date:** [March 18, 2019, 4:25pm UTC](https://forum.serverless.com/t/shared-pre-post-function-code/7710/2 "2019-03-18T16:25:02Z")

</div>

Checkout [https://github.com/middyjs/middy](https://github.com/middyjs/middy) it lets you add middleware before/after functions
