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

@govtechsg/serverless-selective-functions

v1.1.0

Published

Serverless plugin to selectively deploy functions per stage

Downloads

7,075

Readme

Serverless Selective Functions

Serverless License NPM

A Serverless plugin that enables you to selectively deploy functions for specific stages.

Installation

npm i @govtechsg/serverless-selective-functions --save-dev

Add the plugin to your serverless.yml file:

plugins:
  - "@govtechsg/serverless-selective-functions"

Usage

# Everything included by default
addVote:
  handler: src/functionHandlers/addVote/index.handler
  events:
    - http:
        path: /v1/vote
        method: post
        cors: true
  # Not specifying the `stages` property will include this function

# Exclude all prod-[0-9]*
deleteVote:
  handler: src/functionHandlers/deleteVote/index.handler
  events:
    - http:
        path: /v1/vote
        method: delete
        cors: true
  stages:
    exclude: # Specify stages that should exclude this function
      - "prod-[0-9]*" # Regex

# Include all dev-.* except dev-123
# Note that checks will run through the inclusion list first, then the exclusion list
editVote:
  handler: src/functionHandlers/editVote/index.handler
  events:
    - http:
        path: /v1/vote
        method: patch
        cors: true
  stages: # Stage will be tested with both the include and exclude properties
    include:
      - "dev-.*"
    exclude:
      - "dev-123"

# Include dev-123 and all prod-.*
summary:
  handler: src/functionHandlers/summary/index.handler
  events:
    - http:
        path: /v1/summary
        method: get
        cors: true
  stages:
    include:
      - "dev-123"
      - "prod-.*"

Why?

You may want to deploy some functions as specified in your serverless.yml only for a specific stage. A simple approach would be the following:

functions:
  - ${file(serverless/functions/base.yml)}
  - ${file(serverless/functions/${self:provider.stage}.yml)}

Then if you wanted to deploy functions only when the stage is set to offline, you can create a serverless/functions/offline.yml file and populate it with functions meant only for the offline stage.

The approach works for simple cases, but lets say you want to deploy the following functions for 3 stages:

prod: lambdaA, lambdaB
staging: lambdaB
offline: lambdaA, lambdaC

Given that there isn't a common subset of functions, you cannot create a base.yml. If you create a prod.yml with lambdaA + lambdaB, and staging.yml with lambdaB, you will then need to maintain 2 separate definitions of lambdaB which would be error prone. This restricts you to having mutually exclusive sets of functions defined in different yml files, otherwise we tradeoff maintainability.