npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-plugin-microservices

v1.0.3

Published

Serverless plugin to handle microservices architecture

Downloads

9

Readme

Serverless Microservices

npm

A serverless plugin to handle Microservices architectural style that structures application in different Serverless projects.

Usage

Installation

$ npm install serverless-plugin-microservices --save-dev

or using yarn

$ yarn add serverless-plugin-microservices

Configuration

plugins:
  - serverless-plugin-microservices

custom:
  service:
    path: services/*/serverless.yml # glob pattern are supported
    strategy: parallel # deploy strategy, parallel or sequential, default: sequential
    only: # filter discovered services by service name  
      - auth
      - cart
      - products

path: glob pattern that point to service's serverless.yml file.

strategy: this is the default configuration of deploy strategy. Can be overrided by --strategy parameter. This can be used to deploy service with cross-service dependencies that require a sequential deploy in some cases.

only: during services load their serverless.yml are readed and service key (use by Serverless to identify your app name) is used as filter target.

Repository structures

You can use both Mono-Repo or Multi-Repo approach, you can find more info about these pattern here.

Mono-Repo

An example of Mono-Repo organization is placing all services into separate directory under a main services directory.

Your repository structure should be similar to:

myapp
├── serverless.yml
└── services
    ├── auth
    │   ├── handler.js
    │   └── severless.yml
    ├── cart
    │   ├── handler.js
    │   └── severless.yml
    └── products
        ├── handler.js
        └── severless.yml

where the root serverless.yml file contains serverless-plugin-microservices configurations and some globals resources. Every service directory contain a Serverless framework's project that will deployed separatly in the same method you deploy a single project.

With this repository organization you can use a configuration similar to:

plugins:
  - serverless-plugin-microservices

custom:
  service:
    path: services/*/serverless.yml # where "services" is the directory that contain services
    strategy: parallel

Deploy all services using:

serverless microservices init
serverless microservices deploy --stage dev --region us-west-1

Benefits:

  • A complete view of all the services in the same repository
  • Faster changes to services
  • Easiest way to share code between services

Multi-Repo

An Multi-Repo approach use npm or yarn (or even git submodules or composer) package manager to organize your services and download a specific version.

If you are using npm as package manager your repository structure should be similar to:

myapp
├── node_modules
│   ├── auth
│   │   ├── handler.js
│   │   └── severless.yml
│   ├── cart
│   │   ├── handler.js
│   │   └── severless.yml
│   └── products
│       ├── handler.js
│       └── severless.yml
├── package.json
└── serverless.yml

where every npm modules is a separate Serverless projects service, root serverless.yml file contains serverless-plugin-microservices

Your package.json can include service from Github:

"dependencies": {
  "auth": "git://github.com/foo/bar-auth.git",
  "cart": "git://github.com/foo/bar-cart.git",
  "products": "git://github.com/foo/bar-products.git"
}

from private repository:

"dependencies": {
  "auth": "git+ssh://gitlab.com/foo/bar-auth.git",
  "cart": "git+ssh://gitlab.com/foo/bar-cart.git",
  "products": "git+ssh://gitlab.com/foo/bar-products.git"
}

using a specific version or commit id:

"dependencies": {
  "auth": "git+ssh://gitlab.com/foo/bar-auth.git#v1.0.2",
  "cart": "git+ssh://gitlab.com/foo/bar-cart.git#semver:^2.0",
  "products": "git+ssh://gitlab.com/foo/bar-products.git#521747298a3790fde1710f3aa2d03b55020575aa"
}

With this repository organization you can use a configuration similar to:

plugins:
  - serverless-plugin-microservices

custom:
  service:
    path: node_modules/*/serverless.yml # where "node_modules" is the directory that contain npm package
    strategy: parallel
    only: # protection from other potential serverless.yml inside other npm package
      - auth
      - cart
      - products

Note: pay attention that if you use serverless as a npm package it contain templates with a lot of severless.yml files, you must set the 'only' settings inside your root severless.yml file

Benefits:

  • A complete isolation of services dependencies
  • Services can reused for an other application
  • Separate version versioning for each service

Commands

Initialize services

Initialize services using:

serverless microservices init

this will execute npm install on every services directories.

Deploy services

Deploy services using:

serverless microservices deploy --stage dev --region us-west-1

this will execute severless deploy on every services directories with stage and region parameter.

Remove services

Remove services using:

serverless microservices remove --stage dev --region us-west-1

this will execute severless remove on every services directories with stage and region parameter.

TODO

  • [ ] Verbose mode with command output
  • [ ] Handle cross-service dependencies with multiple deploy steps