{"id":19107128,"url":"https://github.com/govtechsg/serverless-selective-functions","last_synced_at":"2025-06-14T13:03:49.260Z","repository":{"id":38403401,"uuid":"321912316","full_name":"GovTechSG/serverless-selective-functions","owner":"GovTechSG","description":"Serverless plugin to selectively deploy functions per stage","archived":false,"fork":false,"pushed_at":"2023-02-04T04:07:09.000Z","size":1798,"stargazers_count":2,"open_issues_count":6,"forks_count":2,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-04-30T18:12:01.994Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GovTechSG.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-16T08:07:48.000Z","updated_at":"2022-03-14T05:34:03.000Z","dependencies_parsed_at":"2023-02-18T13:45:35.983Z","dependency_job_id":null,"html_url":"https://github.com/GovTechSG/serverless-selective-functions","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/GovTechSG/serverless-selective-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fserverless-selective-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fserverless-selective-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fserverless-selective-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fserverless-selective-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GovTechSG","download_url":"https://codeload.github.com/GovTechSG/serverless-selective-functions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GovTechSG%2Fserverless-selective-functions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259820783,"owners_count":22916544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T04:11:21.838Z","updated_at":"2025-06-14T13:03:49.238Z","avatar_url":"https://github.com/GovTechSG.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serverless Selective Functions\n\n[![Serverless][ico-serverless]][link-serverless]\n[![License][ico-license]][link-license]\n[![NPM][ico-npm]][link-npm]\n\nA Serverless plugin that enables you to selectively deploy functions for specific stages.\n\n## Installation\n\n`npm i @govtechsg/serverless-selective-functions --save-dev`\n\nAdd the plugin to your `serverless.yml` file:\n\n```\nplugins:\n  - \"@govtechsg/serverless-selective-functions\"\n```\n\n## Usage\n\n```yaml\n# Everything included by default\naddVote:\n  handler: src/functionHandlers/addVote/index.handler\n  events:\n    - http:\n        path: /v1/vote\n        method: post\n        cors: true\n  # Not specifying the `stages` property will include this function\n\n# Exclude all prod-[0-9]*\ndeleteVote:\n  handler: src/functionHandlers/deleteVote/index.handler\n  events:\n    - http:\n        path: /v1/vote\n        method: delete\n        cors: true\n  stages:\n    exclude: # Specify stages that should exclude this function\n      - \"prod-[0-9]*\" # Regex\n\n# Include all dev-.* except dev-123\n# Note that checks will run through the inclusion list first, then the exclusion list\neditVote:\n  handler: src/functionHandlers/editVote/index.handler\n  events:\n    - http:\n        path: /v1/vote\n        method: patch\n        cors: true\n  stages: # Stage will be tested with both the include and exclude properties\n    include:\n      - \"dev-.*\"\n    exclude:\n      - \"dev-123\"\n\n# Include dev-123 and all prod-.*\nsummary:\n  handler: src/functionHandlers/summary/index.handler\n  events:\n    - http:\n        path: /v1/summary\n        method: get\n        cors: true\n  stages:\n    include:\n      - \"dev-123\"\n      - \"prod-.*\"\n```\n\n## Why?\n\nYou may want to deploy some functions as specified in your `serverless.yml` only for a specific stage. A simple approach would be the following:\n\n```yaml\nfunctions:\n  - ${file(serverless/functions/base.yml)}\n  - ${file(serverless/functions/${self:provider.stage}.yml)}\n```\n\nThen 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.\n\nThe approach works for simple cases, but lets say you want to deploy the following functions for 3 stages:\n\n```yaml\nprod: lambdaA, lambdaB\nstaging: lambdaB\noffline: lambdaA, lambdaC\n```\n\nGiven 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.\n\n[ico-serverless]: http://public.serverless.com/badges/v3.svg\n[ico-license]: https://img.shields.io/github/license/GovTechSG/serverless-selective-functions.svg\n[ico-npm]: https://img.shields.io/npm/v/@govtechsg/serverless-selective-functions.svg\n[link-serverless]: https://www.serverless.com/\n[link-license]: ./LICENSE\n[link-npm]: https://www.npmjs.com/package/@govtechsg/serverless-selective-functions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgovtechsg%2Fserverless-selective-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgovtechsg%2Fserverless-selective-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgovtechsg%2Fserverless-selective-functions/lists"}