@middy/warmup 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Middy warmup middleware
2
+
3
+ <div align="center">
4
+ <img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/master/img/middy-logo.png"/>
5
+ </div>
6
+
7
+ <div align="center">
8
+ <p><strong>Warmup middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda</strong></p>
9
+ </div>
10
+
11
+ <div align="center">
12
+ <p>
13
+ <a href="http://badge.fury.io/js/%40middy%2Fwarmup">
14
+ <img src="https://badge.fury.io/js/%40middy%2Fwarmup.svg" alt="npm version" style="max-width:100%;">
15
+ </a>
16
+ <a href="https://snyk.io/test/github/middyjs/middy">
17
+ <img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
18
+ </a>
19
+ <a href="https://standardjs.com/">
20
+ <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
21
+ </a>
22
+ <a href="https://greenkeeper.io/">
23
+ <img src="https://badges.greenkeeper.io/middyjs/middy.svg" alt="Greenkeeper badge" style="max-width:100%;">
24
+ </a>
25
+ <a href="https://gitter.im/middyjs/Lobby">
26
+ <img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
27
+ </a>
28
+ </p>
29
+ </div>
30
+
31
+ Warmup middleware that helps to reduce the [cold-start issue](https://serverless.com/blog/keep-your-lambdas-warm/). Compatible by default with [`serverless-plugin-warmup`](https://www.npmjs.com/package/serverless-plugin-warmup), but it can be configured to suit your implementation.
32
+
33
+ This middleware allows you to specify a schedule to keep Lambdas that always need to be very responsive warmed-up. It does this by regularly invoking the Lambda, but will terminate early to avoid the actual handler logic from being run.
34
+
35
+ If you use [`serverless-plugin-warmup`](https://www.npmjs.com/package/serverless-plugin-warmup) the scheduling part is done by the plugin and you just have to attach the middleware to your "middyfied" handler. If you don't want to use the plugin you have to create the schedule yourself and define the `isWarmingUp` function to define whether the current event is a warmup event or an actual business logic execution.
36
+
37
+ **Important:** AWS recently announced Lambda [Provisioned Concurrency](https://aws.amazon.com/about-aws/whats-new/2019/12/aws-lambda-announces-provisioned-concurrency/). If you have this enabled, you do not need this middleware.
38
+
39
+ To update your code to use Provisioned Concurrency see:
40
+ - [AWS Console](https://aws.amazon.com/blogs/compute/new-for-aws-lambda-predictable-start-up-times-with-provisioned-concurrency/)
41
+ - [Serverless](https://serverless.com/blog/aws-lambda-provisioned-concurrency/)
42
+ - [Terraform](https://www.terraform.io/docs/providers/aws/r/lambda_provisioned_concurrency_config.html)
43
+
44
+ ## Install
45
+
46
+ To install this middleware you can use NPM:
47
+
48
+ ```bash
49
+ npm install --save @middy/warmup
50
+ ```
51
+
52
+
53
+ ## Options
54
+
55
+ - `isWarmingUp`: a function that accepts the `event` object as a parameter
56
+ and returns `true` if the current event is a warmup event and `false` if it's a regular execution. The default function will check if the `event` object has a `source` property set to `serverless-plugin-warmup`.
57
+
58
+ ## Sample usage
59
+
60
+ ```javascript
61
+ const middy = require('@middy/core')
62
+ const warmup = require('@middy/warmup')
63
+
64
+ const isWarmingUp = (event) => event.isWarmingUp === true
65
+
66
+ const originalHandler = (event, context, cb) => {
67
+ /* ... */
68
+ }
69
+
70
+ const handler = middy(originalHandler)
71
+ .use(warmup({ isWarmingUp }))
72
+ ```
73
+
74
+
75
+ ## Middy documentation and examples
76
+
77
+ For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
78
+
79
+
80
+ ## Contributing
81
+
82
+ Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
83
+
84
+
85
+ ## License
86
+
87
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
88
+
89
+ <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
90
+ <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
91
+ </a>
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import middy from '@middy/core'
2
+
3
+ interface Options {
4
+ isWarmingUp?: (event: any) => boolean
5
+ onWarmup?: (event: any) => void
6
+ }
7
+
8
+ declare function warmup (options?: Options): middy.MiddlewareObj
9
+
10
+ export default warmup
package/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ const defaults = {
4
+ isWarmingUp: event => (event === null || event === void 0 ? void 0 : event.source) === 'serverless-plugin-warmup'
5
+ };
6
+
7
+ const warmupMiddleware = opt => {
8
+ const options = { ...defaults,
9
+ ...opt
10
+ };
11
+
12
+ const warmupMiddlewareBefore = request => {
13
+ if (options.isWarmingUp(request.event)) {
14
+ return 'warmup';
15
+ }
16
+ };
17
+
18
+ return {
19
+ before: warmupMiddlewareBefore
20
+ };
21
+ };
22
+
23
+ module.exports = warmupMiddleware;
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@middy/warmup",
3
+ "version": "2.5.2",
4
+ "description": "Warmup (cold start mitigation) middleware for the middy framework",
5
+ "type": "commonjs",
6
+ "engines": {
7
+ "node": ">=12"
8
+ },
9
+ "engineStrict": true,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "main": "index.js",
14
+ "types": "index.d.ts",
15
+ "files": [
16
+ "index.d.ts"
17
+ ],
18
+ "scripts": {
19
+ "test": "npm run test:unit",
20
+ "test:unit": "ava"
21
+ },
22
+ "license": "MIT",
23
+ "keywords": [
24
+ "Lambda",
25
+ "Middleware",
26
+ "Serverless",
27
+ "Framework",
28
+ "AWS",
29
+ "AWS Lambda",
30
+ "Middy",
31
+ "Warmup",
32
+ "Heart beat",
33
+ "Cold start"
34
+ ],
35
+ "author": {
36
+ "name": "Middy contributors",
37
+ "url": "https://github.com/middyjs/middy/graphs/contributors"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "github:middyjs/middy",
42
+ "directory": "packages/warmup"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/middyjs/middy/issues"
46
+ },
47
+ "homepage": "https://github.com/middyjs/middy#readme",
48
+ "devDependencies": {
49
+ "@middy/core": "^2.5.2"
50
+ },
51
+ "gitHead": "a2bb757a7a13638ae64277f8eecfcf11c1af17d4"
52
+ }