Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serkan-ozal/leanser
AWS Lambda Cleaner - Cleanup resources on AWS Lambda container shutdown (timeout and/or spin-down)
https://github.com/serkan-ozal/leanser
Last synced: 4 months ago
JSON representation
AWS Lambda Cleaner - Cleanup resources on AWS Lambda container shutdown (timeout and/or spin-down)
- Host: GitHub
- URL: https://github.com/serkan-ozal/leanser
- Owner: serkan-ozal
- License: mit
- Created: 2022-09-30T12:59:48.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-30T16:02:58.000Z (over 2 years ago)
- Last Synced: 2024-10-17T00:11:48.384Z (4 months ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 20
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# leanser


AWS Lambda Cleaner - Cleanup resources on AWS Lambda container shutdown (timeout and/or spin-down).
> :warning: You have `500 milliseconds` to complete all of your callbacks before function shutdown.
## Installation
You can add `leanser` package into your AWS Lambda function either by NPM package or by AWS Lambda layer as shown below:
### By NPM package
To install the middleware, you can use NPM:
```
npm install --save leanser
```### By AWS Lambda Layer
You can also add `leanser` as layer into your AWS Lambda function.
```
arn:aws:lambda:${region}:273094347961:layer:leanser:${layer-version}```
**Latest layer version:**  (badge powered by [Globadge serverless](https://www.globadge.com/badges/serverless))
**Note:** In the ARN above, you need to replace `${region}` with the actual AWS region you deployed your AWS Lambda function.
## Usage
```javascript
const { register } = require('leanser');async function myCleaner() {
// Run your custom cleanup logic (close connections, etc ...)
};async function myAnotherCleaner() {
// Run your another custom cleanup logic (close connections, etc ...)
};register(myCleaner, myAnotherCleaner);
exports.handler = async function(event, context) {
// Do something meaningfulreturn {
statusCode: 200,
}
};
```## Configuration
* **Optionally**, you can disable/enable cleaner.
- **By environment variable:**
Set `LEANSER_ENABLE` environment variable to `false` to disable cleaner or to `true` (which is default) to enable cleaner back.
```
LEANSER_ENABLE=false
```## Contributing
Everyone is very welcome to contribute to this repository.
Feel free to [raise issues](https://github.com/serkan-ozal/leanser/issues)
or to [submit Pull Requests](https://github.com/serkan-ozal/leanser/pulls).## License
Licensed under [MIT License](LICENSE).