Share common configuration between services
Requirements:
- Serverless v1.12.x or higher.
- AWS provider
Serverless Plugin that allows you to keep common configuration in a parent serverless.yml
Install via npm in the root of your Serverless service:
npm install serverless-plugin-parent --save-dev
- Add the plugin to the
pluginsarray in your Serverlessserverless.yml:
plugins:
- serverless-plugin-parentThe plugin will recursively search all parent directories for a serverless.yml file until it reaches the user's
home direcory or has gone x number of directories up. The default value is 3 but this can be configured using
custom:
parent:
maxLevels: 2# Optional (Default 3)Per default the parent file will overwrite settings in the service files. If you want the service file to have a higher priority you can change that using
custom:
parent:
overwriteServiceConfig: false # Optional (Default true)<project_root>
- service1
- hello.js
- serverless.yml
- service2
- goodbye.js
- serverless.yml
- serverless.yml
provider:
name: awsstage: ${opt:stage, "Test"}runtime: nodejs8.10role: DefaultRoleresources:
Resources:
DefaultRole:
Type: AWS::IAM::RoleProperties:
Path: /RoleName: ${self:service}-${self:provider.stage}AssumeRolePolicyDocument:
Version: "2012-10-17"Statement:
- Effect: AllowPrincipal:
Service:
- lambda.amazonaws.comAction: sts:AssumeRolePolicies:
- PolicyName: ${self:service}-${self:provider.stage}PolicyDocument:
Version: "2012-10-17"Statement:
- Effect: AllowAction:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEventsResource: arn:aws:logs:${self:provider.region}:*:log-group:/aws/lambda/*:*:*service: Service1plugins:
- serverless-plugin-parentprovider:
environment:
HELLO_MESSAGE: Mholofunctions:
Hello:
handler: hello.handleevents:
- http:
path: hellomethod: getcors: trueservice: Service1provider:
name: awsstage: ${opt:stage, "Test"}runtime: nodejs8.10role: DefaultRoleplugins:
- serverless-plugin-parentprovider:
environment:
HELLO_MESSAGE: Mholofunctions:
Hello:
handler: hello.handleevents:
- http:
path: hellomethod: getcors: trueresources:
Resources:
DefaultRole:
Type: AWS::IAM::RoleProperties:
Path: /RoleName: ${self:service}-${self:provider.stage}AssumeRolePolicyDocument:
Version: "2012-10-17"Statement:
- Effect: AllowPrincipal:
Service:
- lambda.amazonaws.comAction: sts:AssumeRolePolicies:
- PolicyName: ${self:service}-${self:provider.stage}PolicyDocument:
Version: "2012-10-17"Statement:
- Effect: AllowAction:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEventsResource: arn:aws:logs:${self:provider.region}:*:log-group:/aws/lambda/*:*:*<project_root>
- parent
- serverless.yml
- service1
- hello.js
- serverless.yml
- service2
- goodbye.js
- serverless.yml
custom:
parent:
path: ../parent# or path: ../parent/serverless.ymlHelp us making this plugin better and future proof.
- Clone the code
- Install the dependencies with
npm install - Create a feature branch
git checkout -b new_feature - Lint with standard
npm run lint
This software is released under the MIT license. See the license file for more details.