Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Edujugon committed Dec 21, 2022
1 parent a59639e commit fc349fa
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
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.
35 changes: 35 additions & 0 deletions lib/index.js
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;
9 changes: 9 additions & 0 deletions package.json
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"
}

0 comments on commit fc349fa

Please sign in to comment.