-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# serverless-remove-resources | ||
A Serverless Framework plugin for removing resources from your CloudFormation template before deployment. | ||
|
||
## Installation | ||
To install this plugin, run: | ||
|
||
```bash | ||
npm install serverless-remove-resources | ||
``` | ||
|
||
Then, add `serverless-remove-resources` to the plugins array in your Serverless service's serverless.yml file: | ||
|
||
```bash | ||
plugins: | ||
- serverless-remove-resources | ||
``` | ||
|
||
## Usage | ||
To use this plugin, specify the resources you want to delete under the `custom.serverless-remove-resources` key in your serverless.yml file. The value should be a list of resource logical names. | ||
|
||
For example: | ||
|
||
```bash | ||
custom: | ||
serverless-remove-resources: | ||
- IamRoleLambdaExecution | ||
``` | ||
|
||
This will remove the IamRoleLambdaExecution resource from your CloudFormation template before deployment. | ||
|
||
## Note | ||
This plugin should be used with caution, as deleting resources can have unintended consequences. Make sure to thoroughly test any changes made using this plugin before deploying to production. | ||
|
||
## Contribution | ||
We welcome contributions to this project. If you are interested in contributing, please feel free to submit a pull request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use strict"; | ||
|
||
const PLUGIN_NAME = "serverless-remove-resources"; | ||
|
||
const removeResources = (service, resourceNames) => { | ||
const cfTemplate = service.provider.compiledCloudFormationTemplate; | ||
|
||
resourceNames.forEach(name => { | ||
delete cfTemplate.Resources[name]; | ||
}); | ||
}; | ||
|
||
class ServerlessRemoveResourcesPlugin { | ||
constructor(serverless, options) { | ||
this.serverless = serverless; | ||
this.options = options; | ||
this.hooks = { | ||
'before:deploy:deploy': this.beforeDeploy.bind(this) | ||
}; | ||
} | ||
|
||
beforeDeploy() { | ||
const { serverless } = this; | ||
const { service } = serverless; | ||
const { custom } = service; | ||
|
||
if (custom && custom[PLUGIN_NAME] && Array.isArray(custom[PLUGIN_NAME])) { | ||
removeResources(service, custom[PLUGIN_NAME]); | ||
} else { | ||
this.serverless.cli.log(`[${PLUGIN_NAME}] No resources specified for removal`); | ||
} | ||
} | ||
} | ||
|
||
module.exports = ServerlessRemoveResourcesPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "serverless-remove-resources", | ||
"version": "1.0.0", | ||
"description": "A Serverless Framework plugin for removing resources from your CloudFormation template before deployment.", | ||
"main": "lib/index.js", | ||
"keywords": [], | ||
"author": "Eduardo Marcos", | ||
"license": "MIT" | ||
} |