Serverless Plugin Modularize

Modularize your serverless definitions


Allows modularized serverless definitions to be merged into a root project. Making decoupled code more config driven and encapsulated.

Downloads Version License



npm install -D serverless-plugin-modularize


yarn add -D serverless-plugin-modularize


Plugin Dependency

In your projects serverless file, add serverless-plugin-modularize to the list of your plugins:

  - serverless-plugin-modularize

Custom Declaration

Add the following declaration to the custom definiton of your serverless file:

    glob: 'src/**/*.module.yml' # glob pattern

The plugin uses glob patterns to resolve matching modularized files. For a primer on glob usage, visit here. If no glob is provided, the plugin will not merge anything. When matches are found, the result will be dynamically merged into the base serverless.yml definition as required.

Supported Module File Types

  • yaml
  • js
  • json


modularize info

The info command can be used to debug what each module is responsible for. In the example here, running the command will produce the following:

$ npx serverless modularize info
modularize: src/goodbye/goodbye.module.yml 
  "functions": {
    "goodbye": {
      "handler": "src/goodbye/index.goodbye"

modularize: src/hello/hello.module.yml 
  "functions": {
    "hello": {
      "handler": "src/hello/index.hello"
modularize merged

The merged command will display what the serverless definition will look like once all the modules are merged:

$ npx serverless modularize merged
modularize: {
  "functions": {
    "goodbye": {
      "handler": "src/goodbye/index.goodbye",
      "events": [],
      "name": "modular-example-dev-goodbye"
    "hello": {
      "handler": "src/hello/index.hello",
      "events": [],
      "name": "modular-example-dev-hello"
  "plugins": [
  "custom": {
    "modularize": {
      "glob": "src/**/*.module.yml"
  "provider": {
    "stage": "dev",
    "variableSyntax": "\\${([ ~:a-zA-Z0-9._@'\",\\-\\/\\(\\)*?]+?)}",
    "name": "aws",
    "runtime": "nodejs10.x",
    "region": "us-east-1",
    "versionFunctions": true,
    "remoteFunctionData": null
  "resources": {}

Supported Mergeable Properties

To avoid mutating the base serverless framework, only the following properties are supported when merging. Unfortunately to help in merging, please follow the Expected Type(s) from the table below to avoid collisions between arrays and object.

Property Expected Type
provider Object
plugins String[]
custom Object or File Reference
functions Object
resources Object

Sample Project

A simple example can be found here, showing how two lambda resource definitions can be modularized into one project.



  • Array de-duplication
  • Moved merge to run once at beginning only


  • Using deep merge with Ramda instead of es6 syntax


  • Adding Outputs fix to resources merge


  • Fixing merge issue regarding Resources, thanks to LoZeno


  • Removed external dependency that was causing merge duplication


  • Deduplicating non-mergeable array items


  • Adding check for Fn:Get keys
view on Github

Latest commit b2f54ec on Sep 24, 2017

New to serverless?

To get started, pop open your terminal & run:

npm install serverless -g