@beesolve/lambda-keep-active 1.0.5 → 1.1.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/.jsii +8549 -0
- package/API.md +165 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE +0 -2
- package/README.md +5 -3
- package/assets/handler.lambda/index.js +70 -0
- package/bun.lock +1556 -0
- package/lib/cdk.d.ts +14 -0
- package/lib/cdk.js +49 -0
- package/lib/handler-function.d.ts +13 -0
- package/lib/handler-function.js +23 -0
- package/lib/handler.lambda.d.ts +3 -0
- package/lib/handler.lambda.js +38 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/{dist → lib}/runtime.d.ts +7 -10
- package/lib/runtime.js +42 -0
- package/lib/shared.d.ts +1 -0
- package/lib/shared.js +5 -0
- package/package.json +83 -28
- package/dist/cdk.d.ts +0 -19
- package/dist/cdk.js +0 -4
- package/dist/lambda/handler.mjs +0 -4
- package/dist/runtime.js +0 -4
package/API.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# API Reference <a name="API Reference" id="api-reference"></a>
|
|
2
|
+
|
|
3
|
+
## Constructs <a name="Constructs" id="Constructs"></a>
|
|
4
|
+
|
|
5
|
+
### LambdaKeepActive <a name="LambdaKeepActive" id="@beesolve/lambda-keep-active.LambdaKeepActive"></a>
|
|
6
|
+
|
|
7
|
+
#### Initializers <a name="Initializers" id="@beesolve/lambda-keep-active.LambdaKeepActive.Initializer"></a>
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { LambdaKeepActive } from '@beesolve/lambda-keep-active'
|
|
11
|
+
|
|
12
|
+
new LambdaKeepActive(scope: Construct, id: string, props?: LambdaKeepActiveProps)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
| **Name** | **Type** | **Description** |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActive.Initializer.parameter.scope">scope</a></code> | <code>constructs.Construct</code> | *No description.* |
|
|
18
|
+
| <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActive.Initializer.parameter.id">id</a></code> | <code>string</code> | *No description.* |
|
|
19
|
+
| <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActive.Initializer.parameter.props">props</a></code> | <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActiveProps">LambdaKeepActiveProps</a></code> | *No description.* |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
##### `scope`<sup>Required</sup> <a name="scope" id="@beesolve/lambda-keep-active.LambdaKeepActive.Initializer.parameter.scope"></a>
|
|
24
|
+
|
|
25
|
+
- *Type:* constructs.Construct
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
##### `id`<sup>Required</sup> <a name="id" id="@beesolve/lambda-keep-active.LambdaKeepActive.Initializer.parameter.id"></a>
|
|
30
|
+
|
|
31
|
+
- *Type:* string
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
##### `props`<sup>Optional</sup> <a name="props" id="@beesolve/lambda-keep-active.LambdaKeepActive.Initializer.parameter.props"></a>
|
|
36
|
+
|
|
37
|
+
- *Type:* <a href="#@beesolve/lambda-keep-active.LambdaKeepActiveProps">LambdaKeepActiveProps</a>
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
#### Methods <a name="Methods" id="Methods"></a>
|
|
42
|
+
|
|
43
|
+
| **Name** | **Description** |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActive.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
46
|
+
| <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActive.keepActive">keepActive</a></code> | *No description.* |
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
##### `toString` <a name="toString" id="@beesolve/lambda-keep-active.LambdaKeepActive.toString"></a>
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
public toString(): string
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Returns a string representation of this construct.
|
|
57
|
+
|
|
58
|
+
##### `keepActive` <a name="keepActive" id="@beesolve/lambda-keep-active.LambdaKeepActive.keepActive"></a>
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
public keepActive(lambda: IFunction): void
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
###### `lambda`<sup>Required</sup> <a name="lambda" id="@beesolve/lambda-keep-active.LambdaKeepActive.keepActive.parameter.lambda"></a>
|
|
65
|
+
|
|
66
|
+
- *Type:* aws-cdk-lib.aws_lambda.IFunction
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
71
|
+
|
|
72
|
+
| **Name** | **Description** |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActive.isConstruct">isConstruct</a></code> | Checks if `x` is a construct. |
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
##### `isConstruct` <a name="isConstruct" id="@beesolve/lambda-keep-active.LambdaKeepActive.isConstruct"></a>
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { LambdaKeepActive } from '@beesolve/lambda-keep-active'
|
|
82
|
+
|
|
83
|
+
LambdaKeepActive.isConstruct(x: any)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Checks if `x` is a construct.
|
|
87
|
+
|
|
88
|
+
Use this method instead of `instanceof` to properly detect `Construct`
|
|
89
|
+
instances, even when the construct library is symlinked.
|
|
90
|
+
|
|
91
|
+
Explanation: in JavaScript, multiple copies of the `constructs` library on
|
|
92
|
+
disk are seen as independent, completely different libraries. As a
|
|
93
|
+
consequence, the class `Construct` in each copy of the `constructs` library
|
|
94
|
+
is seen as a different class, and an instance of one class will not test as
|
|
95
|
+
`instanceof` the other class. `npm install` will not create installations
|
|
96
|
+
like this, but users may manually symlink construct libraries together or
|
|
97
|
+
use a monorepo tool: in those cases, multiple copies of the `constructs`
|
|
98
|
+
library can be accidentally installed, and `instanceof` will behave
|
|
99
|
+
unpredictably. It is safest to avoid using `instanceof`, and using
|
|
100
|
+
this type-testing method instead.
|
|
101
|
+
|
|
102
|
+
###### `x`<sup>Required</sup> <a name="x" id="@beesolve/lambda-keep-active.LambdaKeepActive.isConstruct.parameter.x"></a>
|
|
103
|
+
|
|
104
|
+
- *Type:* any
|
|
105
|
+
|
|
106
|
+
Any object.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
111
|
+
|
|
112
|
+
| **Name** | **Type** | **Description** |
|
|
113
|
+
| --- | --- | --- |
|
|
114
|
+
| <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActive.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
##### `node`<sup>Required</sup> <a name="node" id="@beesolve/lambda-keep-active.LambdaKeepActive.property.node"></a>
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
public readonly node: Node;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- *Type:* constructs.Node
|
|
125
|
+
|
|
126
|
+
The tree node.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
## Structs <a name="Structs" id="Structs"></a>
|
|
132
|
+
|
|
133
|
+
### LambdaKeepActiveProps <a name="LambdaKeepActiveProps" id="@beesolve/lambda-keep-active.LambdaKeepActiveProps"></a>
|
|
134
|
+
|
|
135
|
+
#### Initializer <a name="Initializer" id="@beesolve/lambda-keep-active.LambdaKeepActiveProps.Initializer"></a>
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { LambdaKeepActiveProps } from '@beesolve/lambda-keep-active'
|
|
139
|
+
|
|
140
|
+
const lambdaKeepActiveProps: LambdaKeepActiveProps = { ... }
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
144
|
+
|
|
145
|
+
| **Name** | **Type** | **Description** |
|
|
146
|
+
| --- | --- | --- |
|
|
147
|
+
| <code><a href="#@beesolve/lambda-keep-active.LambdaKeepActiveProps.property.enableLogs">enableLogs</a></code> | <code>boolean</code> | If disabled no logs are logged to CloudWatch. |
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
##### `enableLogs`<sup>Optional</sup> <a name="enableLogs" id="@beesolve/lambda-keep-active.LambdaKeepActiveProps.property.enableLogs"></a>
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
public readonly enableLogs: boolean;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- *Type:* boolean
|
|
158
|
+
- *Default:* true
|
|
159
|
+
|
|
160
|
+
If disabled no logs are logged to CloudWatch.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
## [1.1.1](https://github.com/beesolve/lambda-keep-active/compare/v1.1.0...v1.1.1) (2025-12-03)
|
|
3
|
+
|
|
4
|
+
## [1.1.0](https://github.com/beesolve/lambda-keep-active/compare/v1.0.5...v1.1.0) (2025-12-03)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* change to projen ([2ed9a40](https://github.com/beesolve/lambda-keep-active/commit/2ed9a4040373b7353d4d8b08601151ceb2e8aa07))
|
|
10
|
+
* fix config ([307d174](https://github.com/beesolve/lambda-keep-active/commit/307d1744a51f2f0dd5af18c653fa9cf51df27c6d))
|
|
11
|
+
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Lambda Keep Active
|
|
2
2
|
|
|
3
|
+
[](https://constructs.dev/packages/@beesolve/lambda-keep-active)
|
|
4
|
+
|
|
3
5
|
> A function becomes inactive when it has been idle long enough for Lambda to reclaim the external resources that were configured for it. When you try to invoke a function that is inactive, the invocation fails and Lambda sets the function to pending state until the function resources are recreated. If Lambda fails to recreate the resources, the function returns to the inactive state. You might need to resolve any errors and redeploy your function to restore it to the active state.
|
|
4
6
|
>
|
|
5
7
|
> [Lambda function states](https://docs.aws.amazon.com/lambda/latest/dg/functions-states.html)
|
|
@@ -24,7 +26,7 @@ npm i @beesolve/lambda-keep-active
|
|
|
24
26
|
|
|
25
27
|
```ts
|
|
26
28
|
// stack.ts
|
|
27
|
-
import { LambdaKeepActive } from "@beesolve/lambda-keep-active
|
|
29
|
+
import { LambdaKeepActive } from "@beesolve/lambda-keep-active";
|
|
28
30
|
|
|
29
31
|
const warmer = new LambdaKeepActive(this, "KeepAliveLambda");
|
|
30
32
|
|
|
@@ -37,7 +39,7 @@ For Node.js Lambda handlers you can use `keptActive` wrapper like this:
|
|
|
37
39
|
|
|
38
40
|
```ts
|
|
39
41
|
// handler.ts
|
|
40
|
-
import { keptActive } from "@beesolve/lambda-keep-active
|
|
42
|
+
import { keptActive } from "@beesolve/lambda-keep-active";
|
|
41
43
|
|
|
42
44
|
export const handler = keptActive(async () => {
|
|
43
45
|
// your handler code
|
|
@@ -48,7 +50,7 @@ For [Bun Lambda handlers](https://github.com/BeeSolve/lambda-bun-runtime) you ca
|
|
|
48
50
|
|
|
49
51
|
```ts
|
|
50
52
|
// bunHandler.ts
|
|
51
|
-
import { keptActiveFetch } from "@beesolve/lambda-keep-active
|
|
53
|
+
import { keptActiveFetch } from "@beesolve/lambda-keep-active";
|
|
52
54
|
|
|
53
55
|
export default {
|
|
54
56
|
fetch: keptActiveFetch(async (request: Request): Promise<Response> => {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/handler.lambda.ts
|
|
21
|
+
var handler_lambda_exports = {};
|
|
22
|
+
__export(handler_lambda_exports, {
|
|
23
|
+
handler: () => handler
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(handler_lambda_exports);
|
|
26
|
+
var import_client_lambda = require("@aws-sdk/client-lambda");
|
|
27
|
+
var import_client_resource_groups_tagging_api = require("@aws-sdk/client-resource-groups-tagging-api");
|
|
28
|
+
|
|
29
|
+
// src/shared.ts
|
|
30
|
+
var keepActivePing = "$$keepActivePing$$";
|
|
31
|
+
|
|
32
|
+
// src/handler.lambda.ts
|
|
33
|
+
var lambdaClient = new import_client_lambda.LambdaClient();
|
|
34
|
+
var taggingClient = new import_client_resource_groups_tagging_api.ResourceGroupsTaggingAPIClient();
|
|
35
|
+
var enableLogs = process.env.ENABLE_LOGS === "true";
|
|
36
|
+
var handler = async (event) => {
|
|
37
|
+
const { action } = event;
|
|
38
|
+
if (action == null) return;
|
|
39
|
+
if (action !== "lambdaKeepActive") return;
|
|
40
|
+
let nextToken;
|
|
41
|
+
do {
|
|
42
|
+
const { ResourceTagMappingList = [], PaginationToken } = await taggingClient.send(
|
|
43
|
+
new import_client_resource_groups_tagging_api.GetResourcesCommand({
|
|
44
|
+
ResourceTypeFilters: ["lambda:function"],
|
|
45
|
+
ResourcesPerPage: 25,
|
|
46
|
+
TagFilters: [{ Key: "keepActive", Values: ["true"] }],
|
|
47
|
+
PaginationToken: nextToken
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
nextToken = PaginationToken;
|
|
51
|
+
await Promise.all(
|
|
52
|
+
ResourceTagMappingList.map(async (resource) => {
|
|
53
|
+
await lambdaClient.send(
|
|
54
|
+
new import_client_lambda.InvokeCommand({
|
|
55
|
+
FunctionName: resource.ResourceARN,
|
|
56
|
+
InvocationType: "Event",
|
|
57
|
+
Payload: JSON.stringify({ [keepActivePing]: true })
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
if (enableLogs) {
|
|
61
|
+
console.info(`Invoked ${resource.ResourceARN}`);
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
} while (nextToken != null && nextToken !== "");
|
|
66
|
+
};
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
handler
|
|
70
|
+
});
|