Coder Social home page Coder Social logo

economysizegeek / serverless-dir-config-plugin Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 1.0 9 KB

This is a plugin makes it possible to keep your function and resource definitions in separate files in a directory structure instead of the serverless.yml

License: MIT License

JavaScript 100.00%
serverless-plugin serverless serverless-deployments

serverless-dir-config-plugin's Introduction

serverless-dir-config-plugin

This is a plugin makes it possible to keep your function and resource definitions in separate files in a directory structure instead of the serverless.yml

#Installation External Plugins are added on a per service basis and are not applied globally. Make sure you are in your Service's root directory, then install the corresponding Plugin with the help of NPM:

npm install --save serverless-dir-config-plugin

In your service create a directory structure like

mkdir serverless
mkdir serverless/functions
mkdir serverless/resources

The plugin will look in these directories for files ending in .yml to load in. You can nest them any way you want. They use the same structure of yaml as the way they are included in the serverless.yml. They also support all the variable resolution that the main file supports.

hello:
  handler: lib/handler.hello
  role: BasicLambdaRole
  events:
    - http:
        path: hello
        method: get
        integration: lambda-proxy

Keep in mind for the resources there are multiple resource types. I tend to create directories for different groupings (ima, dynamodb,etc)

Make sure you include the type first (Resources/Outputs etc):

Resources:
  BasicLambdaRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: ${self:service}-${self:provider.stage}-BasicLambdaRole
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com
            Action: sts:AssumeRole
      Policies:
        - PolicyName: ${self:service}-${self:provider.stage}-BasicLambdaPolicy
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: Allow
                Action:
                  - "logs:*"
                  - "cloudwatch:*"
                Resource: "*"

Configuration

You need to add it to the plugin section of the serverless.yml

plugins:
  - serverless-dir-config-plugin

Currently the only thing you can configure is if it shows what resources and functions are being loaded. If you don't want to see that - set quiet to true.


custom:
  dirconfig:
      quiet: false

Warnings

Serverless.js doesn't provide hooks to append to the config file. This plugin ends up making some assumptions to work.

  1. Currently the framework loads all the plugins before it does anything. This allows the plugin to look for the files and append them to the configuration before anything happens.

  2. After the configuration is loaded all the variables get resolved. The plugin monkeypatches this process so it can add in function names once the variables are all set.

This means that right now the way the plugin works is very fragile. If the Serverless.js changes the way they load things - this plugin will break. I am hoping that after confirming that this plugin is useful I will submit a PR that looks at giving plugins access to the hooks that I'm basically inventing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.