@bancs/serverless-stages-plugin
v1.0.0
Published
Serverless plugin that restricts deployments to a configured list of stages.
Downloads
103
Maintainers
Readme
@bancs/serverless-stages-plugin
A Serverless Framework plugin that restricts deployments to a configured list of allowed stages.
If you attempt to deploy to a stage that isn't in your custom.stages list, the deployment is aborted with a clear error message — preventing accidental deploys to the wrong environment.
Installation
npm install --save-dev @bancs/serverless-stages-pluginUsage
Add the plugin to your serverless.yml and define the allowed stages in custom.stages:
service: my-service
plugins:
- @bancs/serverless-stages-plugin
custom:
stages:
- dev
- staging
- prod
provider:
name: aws
stage: ${opt:stage, 'dev'}Now any deploy to a stage not in the list will fail immediately:
$ serverless deploy --stage qa
Error: 'qa' is not a valid deployment stage.
Add it to your serverless.yml's "custom.stages" section.Configuration
custom:
# Required. List the stages you allow deployments to.
stages:
- dev
- staging
- prod
# A single string is also valid.
# stages: prodHow it works
The plugin hooks into before:package:initialize and before:deploy:function:initialize. On each hook it:
- Reads the stage from
--stageCLI option, falling back toprovider.stage. - Reads the allowed stages from
custom.stages. - Throws if
custom.stagesis missing or if the current stage is not in the list.
Contributing
See CONTRIBUTING.md.
Code of Conduct
See CODE_OF_CONDUCT.md.
