# Shared Handlers

**URL:** <https://forum.serverless.com/t/shared-handlers/7200>\
**Category:** Serverless Framework\
**Tags:** lambda\
**Created:** [January 29, 2019, 4:51pm UTC](https://forum.serverless.com/t/shared-handlers/7200 "2019-01-29T16:51:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![perry\_hoekstra](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@perry\_hoekstra](https://forum.serverless.com/u/perry_hoekstra)\
**Post date:** [January 29, 2019, 4:51pm UTC](https://forum.serverless.com/t/shared-handlers/7200/1 "2019-01-29T16:51:36Z")

</div>

In using the Serverless framework, is it possible to have shared handlers?

If you have multiple domains and there are some handlers that are shared across those domains, how would you reference them within the **servlerless.yml** file? We have common handlers where their functionality is different based on parameters passed in through the environment section of the **serverless.yml** file but cannot figure out how to reference them correctly through the **serverless.yml** file, more specifically, the **handler** entry.

I have tried entries such as:

```auto
retrieveFoo:
  handler: common/common_retrieve.retrieve

```

and the directory structure looks like this

```auto
common:
  common_retrieve.js

fooA:
  serverless.yml <- retrieveFoo defined here
  other_functions.js

```

However, this does not seem to work.

I took a look at [Function handler from folder outside project](http://forum.serverless.com/t/function-handler-from-folder-outside-project/5421) but there was no joy there, I would receive an error stating: No matching handler found for ‘common/common\_retreive’ when I did a ‘serverless deploy’.

---

<div class="post-metadata">

**Author:** ![dgburton](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dgburton/32/3516_2.png) [@dgburton](https://forum.serverless.com/u/dgburton)\
**Post date:** [August 11, 2019, 12:46pm UTC](https://forum.serverless.com/t/shared-handlers/7200/2 "2019-08-11T12:46:24Z")

</div>

Got the same question!..

---

<div class="post-metadata">

**Author:** ![ngoue](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ngoue/32/3562_2.png) [@ngoue](https://forum.serverless.com/u/ngoue)\
**Post date:** [August 26, 2019, 7:38pm UTC](https://forum.serverless.com/t/shared-handlers/7200/3 "2019-08-26T19:38:39Z")

</div>

By default, only files inside your service directory get packaged for deployment.

However, this seems to be a common practice to help keep things DRY and somebody has already written a handy plugin to help include external files when you deploy. Here’s what you can do:

```
$ npm install serverless-package-external --save-dev

```

Then in your `serverless.yml` file:

```
plugins:
  - serverless-package-external

custom:
  packageExternal:
    external:
      - "../common"

functions:
  retrieveFoo:
    handler: common/common_retrieve.retrieve.js

```

This tells `serverless` to include the `common` directory in your deployment package and copies it to the root of your `fooA` service directory. So the final package structure looks like this:

```
fooA/
  common/ 
    common_retrieve.js
  serverless.yml
  other_functions.js

```

Now you only have your `common/` code written in a single location, and any service can get those files at deployment and use them.
