@jjrawlins/cdk-iam-policy-builder-helper 0.0.85 → 0.0.86
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 +3 -3
- package/cdkiampolicybuilderhelper/jsii/jsii.go +2 -2
- package/cdkiampolicybuilderhelper/version +1 -1
- package/lib/constructs/Actions.d.ts +19 -0
- package/lib/constructs/Actions.js +20 -1
- package/methods_list.txt +17 -0
- package/node_modules/@aws/lambda-invoke-store/README.md +35 -27
- package/node_modules/@aws/lambda-invoke-store/dist-cjs/invoke-store.js +104 -46
- package/node_modules/@aws/lambda-invoke-store/dist-es/invoke-store.js +104 -46
- package/node_modules/@aws/lambda-invoke-store/dist-types/invoke-store.benchmark.d.ts +1 -0
- package/node_modules/@aws/lambda-invoke-store/dist-types/invoke-store.d.ts +40 -47
- package/node_modules/@aws/lambda-invoke-store/package.json +2 -2
- package/node_modules/@aws-sdk/client-iam/package.json +3 -3
- package/node_modules/@aws-sdk/client-sso/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-node/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +2 -2
- package/node_modules/@aws-sdk/middleware-recursion-detection/dist-cjs/recursionDetectionMiddleware.js +2 -1
- package/node_modules/@aws-sdk/middleware-recursion-detection/dist-es/recursionDetectionMiddleware.js +2 -1
- package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/package.json +2 -2
- package/node_modules/@aws-sdk/token-providers/package.json +2 -2
- package/package.json +2 -2
package/methods_list.txt
CHANGED
|
@@ -775,6 +775,7 @@ appstream:AssociateAppBlockBuilderAppBlock
|
|
|
775
775
|
appstream:AssociateApplicationFleet
|
|
776
776
|
appstream:AssociateApplicationToEntitlement
|
|
777
777
|
appstream:AssociateFleet
|
|
778
|
+
appstream:AssociateSoftwareToImageBuilder
|
|
778
779
|
appstream:BatchAssociateUserStack
|
|
779
780
|
appstream:BatchDisassociateUserStack
|
|
780
781
|
appstream:CopyImage
|
|
@@ -784,9 +785,11 @@ appstream:CreateAppBlockBuilderStreamingURL
|
|
|
784
785
|
appstream:CreateApplication
|
|
785
786
|
appstream:CreateDirectoryConfig
|
|
786
787
|
appstream:CreateEntitlement
|
|
788
|
+
appstream:CreateExportImageTask
|
|
787
789
|
appstream:CreateFleet
|
|
788
790
|
appstream:CreateImageBuilder
|
|
789
791
|
appstream:CreateImageBuilderStreamingURL
|
|
792
|
+
appstream:CreateImportedImage
|
|
790
793
|
appstream:CreateStack
|
|
791
794
|
appstream:CreateStreamingURL
|
|
792
795
|
appstream:CreateThemeForStack
|
|
@@ -811,6 +814,7 @@ appstream:DescribeAppBlockBuilders
|
|
|
811
814
|
appstream:DescribeAppBlocks
|
|
812
815
|
appstream:DescribeApplicationFleetAssociations
|
|
813
816
|
appstream:DescribeApplications
|
|
817
|
+
appstream:DescribeAppLicenseUsage
|
|
814
818
|
appstream:DescribeDirectoryConfigs
|
|
815
819
|
appstream:DescribeEntitlements
|
|
816
820
|
appstream:DescribeFleets
|
|
@@ -818,6 +822,7 @@ appstream:DescribeImageBuilders
|
|
|
818
822
|
appstream:DescribeImagePermissions
|
|
819
823
|
appstream:DescribeImages
|
|
820
824
|
appstream:DescribeSessions
|
|
825
|
+
appstream:DescribeSoftwareAssociations
|
|
821
826
|
appstream:DescribeStacks
|
|
822
827
|
appstream:DescribeThemeForStack
|
|
823
828
|
appstream:DescribeUsageReportSubscriptions
|
|
@@ -828,15 +833,19 @@ appstream:DisassociateAppBlockBuilderAppBlock
|
|
|
828
833
|
appstream:DisassociateApplicationFleet
|
|
829
834
|
appstream:DisassociateApplicationFromEntitlement
|
|
830
835
|
appstream:DisassociateFleet
|
|
836
|
+
appstream:DisassociateSoftwareFromImageBuilder
|
|
831
837
|
appstream:EnableUser
|
|
832
838
|
appstream:ExpireSession
|
|
839
|
+
appstream:GetExportImageTask
|
|
833
840
|
appstream:ListAssociatedFleets
|
|
834
841
|
appstream:ListAssociatedStacks
|
|
835
842
|
appstream:ListEntitledApplications
|
|
843
|
+
appstream:ListExportImageTasks
|
|
836
844
|
appstream:ListTagsForResource
|
|
837
845
|
appstream:StartAppBlockBuilder
|
|
838
846
|
appstream:StartFleet
|
|
839
847
|
appstream:StartImageBuilder
|
|
848
|
+
appstream:StartSoftwareDeploymentToImageBuilder
|
|
840
849
|
appstream:StopAppBlockBuilder
|
|
841
850
|
appstream:StopFleet
|
|
842
851
|
appstream:StopImageBuilder
|
|
@@ -6781,6 +6790,9 @@ ecs:UpdateServicePrimaryTaskSet
|
|
|
6781
6790
|
ecs:UpdateTaskProtection
|
|
6782
6791
|
ecs:UpdateTaskSet
|
|
6783
6792
|
eks-auth:AssumeRoleForPodIdentity
|
|
6793
|
+
eks-mcp:CallPrivilegedTool
|
|
6794
|
+
eks-mcp:CallReadOnlyTool
|
|
6795
|
+
eks-mcp:InvokeMcp
|
|
6784
6796
|
eks:AccessKubernetesApi
|
|
6785
6797
|
eks:AssociateAccessPolicy
|
|
6786
6798
|
eks:AssociateEncryptionConfig
|
|
@@ -7334,6 +7346,7 @@ es:CreateApplication
|
|
|
7334
7346
|
es:CreateDomain
|
|
7335
7347
|
es:CreateElasticsearchDomain
|
|
7336
7348
|
es:CreateElasticsearchServiceRole
|
|
7349
|
+
es:CreateIndex
|
|
7337
7350
|
es:CreateOutboundConnection
|
|
7338
7351
|
es:CreateOutboundCrossClusterSearchConnection
|
|
7339
7352
|
es:CreatePackage
|
|
@@ -7347,6 +7360,7 @@ es:DeleteElasticsearchDomain
|
|
|
7347
7360
|
es:DeleteElasticsearchServiceRole
|
|
7348
7361
|
es:DeleteInboundConnection
|
|
7349
7362
|
es:DeleteInboundCrossClusterSearchConnection
|
|
7363
|
+
es:DeleteIndex
|
|
7350
7364
|
es:DeleteOutboundConnection
|
|
7351
7365
|
es:DeleteOutboundCrossClusterSearchConnection
|
|
7352
7366
|
es:DeletePackage
|
|
@@ -7389,6 +7403,7 @@ es:GetCompatibleVersions
|
|
|
7389
7403
|
es:GetDataSource
|
|
7390
7404
|
es:GetDirectQueryDataSource
|
|
7391
7405
|
es:GetDomainMaintenanceStatus
|
|
7406
|
+
es:GetIndex
|
|
7392
7407
|
es:GetPackageVersionHistory
|
|
7393
7408
|
es:GetUpgradeHistory
|
|
7394
7409
|
es:GetUpgradeStatus
|
|
@@ -7423,6 +7438,7 @@ es:UpdateDataSource
|
|
|
7423
7438
|
es:UpdateDirectQueryDataSource
|
|
7424
7439
|
es:UpdateDomainConfig
|
|
7425
7440
|
es:UpdateElasticsearchDomainConfig
|
|
7441
|
+
es:UpdateIndex
|
|
7426
7442
|
es:UpdatePackage
|
|
7427
7443
|
es:UpdatePackageScope
|
|
7428
7444
|
es:UpdateScheduledAction
|
|
@@ -8777,6 +8793,7 @@ guardduty:ListTagsForResource
|
|
|
8777
8793
|
guardduty:ListThreatEntitySets
|
|
8778
8794
|
guardduty:ListThreatIntelSets
|
|
8779
8795
|
guardduty:ListTrustedEntitySets
|
|
8796
|
+
guardduty:SendObjectMalwareScan
|
|
8780
8797
|
guardduty:SendSecurityTelemetry
|
|
8781
8798
|
guardduty:StartMalwareScan
|
|
8782
8799
|
guardduty:StartMonitoringMembers
|
|
@@ -33,19 +33,20 @@ export const handler = async (event, context) => {
|
|
|
33
33
|
// The RIC has already initialized the InvokeStore with requestId and X-Ray traceId
|
|
34
34
|
|
|
35
35
|
// Access Lambda context data
|
|
36
|
-
|
|
36
|
+
const invokeStore = await InvokeStore.getInstanceAsync();
|
|
37
|
+
console.log(`Processing request: ${invokeStore.getRequestId()}`);
|
|
37
38
|
|
|
38
39
|
// Store custom data
|
|
39
|
-
|
|
40
|
+
invokeStore.set("userId", event.userId);
|
|
40
41
|
|
|
41
42
|
// Data persists across async operations
|
|
42
43
|
await processData(event);
|
|
43
44
|
|
|
44
45
|
// Retrieve custom data
|
|
45
|
-
const userId =
|
|
46
|
+
const userId = invokeStore.get("userId");
|
|
46
47
|
|
|
47
48
|
return {
|
|
48
|
-
requestId:
|
|
49
|
+
requestId: invokeStore.getRequestId(),
|
|
49
50
|
userId,
|
|
50
51
|
};
|
|
51
52
|
};
|
|
@@ -53,89 +54,96 @@ export const handler = async (event, context) => {
|
|
|
53
54
|
// Context is preserved in async operations
|
|
54
55
|
async function processData(event) {
|
|
55
56
|
// Still has access to the same invoke context
|
|
56
|
-
|
|
57
|
+
const invokeStore = await InvokeStore.getInstanceAsync();
|
|
58
|
+
console.log(`Processing in same context: ${invokeStore.getRequestId()}`);
|
|
57
59
|
|
|
58
60
|
// Can set additional data
|
|
59
|
-
|
|
61
|
+
invokeStore.set("processedData", { result: "success" });
|
|
60
62
|
}
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
## API Reference
|
|
64
66
|
|
|
65
|
-
### InvokeStore.
|
|
67
|
+
### InvokeStore.getInstanceAsync()
|
|
68
|
+
First, get an instance of the InvokeStore:
|
|
69
|
+
```typescript
|
|
70
|
+
const invokeStore = await InvokeStore.getInstanceAsync();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### invokeStore.getContext()
|
|
66
74
|
|
|
67
75
|
Returns the complete current context or `undefined` if outside a context.
|
|
68
76
|
|
|
69
77
|
```typescript
|
|
70
|
-
const context =
|
|
78
|
+
const context = invokeStore.getContext();
|
|
71
79
|
```
|
|
72
80
|
|
|
73
|
-
###
|
|
81
|
+
### invokeStore.get(key)
|
|
74
82
|
|
|
75
83
|
Gets a value from the current context.
|
|
76
84
|
|
|
77
85
|
```typescript
|
|
78
|
-
const requestId =
|
|
79
|
-
const customValue =
|
|
86
|
+
const requestId = invokeStore.get(InvokeStoreBase.PROTECTED_KEYS.REQUEST_ID);
|
|
87
|
+
const customValue = invokeStore.get("customKey");
|
|
80
88
|
```
|
|
81
89
|
|
|
82
|
-
###
|
|
90
|
+
### invokeStore.set(key, value)
|
|
83
91
|
|
|
84
92
|
Sets a custom value in the current context. Protected Lambda fields cannot be modified.
|
|
85
93
|
|
|
86
94
|
```typescript
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
invokeStore.set("userId", "user-123");
|
|
96
|
+
invokeStore.set("timestamp", Date.now());
|
|
89
97
|
|
|
90
98
|
// This will throw an error:
|
|
91
|
-
//
|
|
99
|
+
// invokeStore.set(InvokeStoreBase.PROTECTED_KEYS.REQUEST_ID, 'new-id');
|
|
92
100
|
```
|
|
93
101
|
|
|
94
|
-
###
|
|
102
|
+
### invokeStore.getRequestId()
|
|
95
103
|
|
|
96
104
|
Convenience method to get the current request ID.
|
|
97
105
|
|
|
98
106
|
```typescript
|
|
99
|
-
const requestId =
|
|
107
|
+
const requestId = invokeStore.getRequestId(); // Returns '-' if outside context
|
|
100
108
|
```
|
|
101
109
|
|
|
102
|
-
###
|
|
110
|
+
### invokeStore.getTenantId()
|
|
103
111
|
|
|
104
112
|
Convenience method to get the tenant ID.
|
|
105
113
|
|
|
106
114
|
```typescript
|
|
107
|
-
const requestId =
|
|
115
|
+
const requestId = invokeStore.getTenantId();
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
###
|
|
118
|
+
### invokeStore.getXRayTraceId()
|
|
111
119
|
|
|
112
120
|
Convenience method to get the current [X-Ray trace ID](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces). This ID is used for distributed tracing across AWS services.
|
|
113
121
|
|
|
114
122
|
```typescript
|
|
115
|
-
const traceId =
|
|
123
|
+
const traceId = invokeStore.getXRayTraceId(); // Returns undefined if not set or outside context
|
|
116
124
|
```
|
|
117
125
|
|
|
118
|
-
###
|
|
126
|
+
### invokeStore.hasContext()
|
|
119
127
|
|
|
120
128
|
Checks if code is currently running within an invoke context.
|
|
121
129
|
|
|
122
130
|
```typescript
|
|
123
|
-
if (
|
|
131
|
+
if (invokeStore.hasContext()) {
|
|
124
132
|
// We're inside an invoke context
|
|
125
133
|
}
|
|
126
134
|
```
|
|
127
135
|
|
|
128
|
-
###
|
|
136
|
+
### invokeStore.run(context, fn)
|
|
129
137
|
|
|
130
138
|
> **Note**: This method is primarily used by the Lambda Runtime Interface Client (RIC) to initialize the context for each invocation. Lambda function developers typically don't need to call this method directly.
|
|
131
139
|
|
|
132
140
|
Runs a function within an invoke context.
|
|
133
141
|
|
|
134
142
|
```typescript
|
|
135
|
-
|
|
143
|
+
invokeStore.run(
|
|
136
144
|
{
|
|
137
|
-
[
|
|
138
|
-
[
|
|
145
|
+
[InvokeStoreBase.PROTECTED_KEYS.REQUEST_ID]: "request-123",
|
|
146
|
+
[InvokeStoreBase.PROTECTED_KEYS.X_RAY_TRACE_ID]: "trace-456", // Optional X-Ray trace ID
|
|
139
147
|
customField: "value", // Optional custom fields
|
|
140
148
|
},
|
|
141
149
|
() => {
|
|
@@ -1,66 +1,124 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var async_hooks = require('async_hooks');
|
|
4
|
-
|
|
5
|
-
const noGlobalAwsLambda = process.env["AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA"] === "1" ||
|
|
6
|
-
process.env["AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA"] === "true";
|
|
7
|
-
if (!noGlobalAwsLambda) {
|
|
8
|
-
globalThis.awslambda = globalThis.awslambda || {};
|
|
9
|
-
}
|
|
10
3
|
const PROTECTED_KEYS = {
|
|
11
|
-
REQUEST_ID: Symbol("_AWS_LAMBDA_REQUEST_ID"),
|
|
12
|
-
X_RAY_TRACE_ID: Symbol("_AWS_LAMBDA_X_RAY_TRACE_ID"),
|
|
13
|
-
TENANT_ID: Symbol("_AWS_LAMBDA_TENANT_ID"),
|
|
4
|
+
REQUEST_ID: Symbol.for("_AWS_LAMBDA_REQUEST_ID"),
|
|
5
|
+
X_RAY_TRACE_ID: Symbol.for("_AWS_LAMBDA_X_RAY_TRACE_ID"),
|
|
6
|
+
TENANT_ID: Symbol.for("_AWS_LAMBDA_TENANT_ID"),
|
|
14
7
|
};
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const NO_GLOBAL_AWS_LAMBDA = ["true", "1"].includes(process.env?.AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA ?? "");
|
|
9
|
+
if (!NO_GLOBAL_AWS_LAMBDA) {
|
|
10
|
+
globalThis.awslambda = globalThis.awslambda || {};
|
|
11
|
+
}
|
|
12
|
+
class InvokeStoreBase {
|
|
17
13
|
static PROTECTED_KEYS = PROTECTED_KEYS;
|
|
18
|
-
|
|
19
|
-
return
|
|
14
|
+
isProtectedKey(key) {
|
|
15
|
+
return Object.values(PROTECTED_KEYS).includes(key);
|
|
16
|
+
}
|
|
17
|
+
getRequestId() {
|
|
18
|
+
return this.get(PROTECTED_KEYS.REQUEST_ID) ?? "-";
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
return this.
|
|
20
|
+
getXRayTraceId() {
|
|
21
|
+
return this.get(PROTECTED_KEYS.X_RAY_TRACE_ID);
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return context?.[key];
|
|
23
|
+
getTenantId() {
|
|
24
|
+
return this.get(PROTECTED_KEYS.TENANT_ID);
|
|
27
25
|
}
|
|
28
|
-
|
|
26
|
+
}
|
|
27
|
+
class InvokeStoreSingle extends InvokeStoreBase {
|
|
28
|
+
currentContext;
|
|
29
|
+
getContext() {
|
|
30
|
+
return this.currentContext;
|
|
31
|
+
}
|
|
32
|
+
hasContext() {
|
|
33
|
+
return this.currentContext !== undefined;
|
|
34
|
+
}
|
|
35
|
+
get(key) {
|
|
36
|
+
return this.currentContext?.[key];
|
|
37
|
+
}
|
|
38
|
+
set(key, value) {
|
|
29
39
|
if (this.isProtectedKey(key)) {
|
|
30
|
-
throw new Error(`Cannot modify protected Lambda context field`);
|
|
40
|
+
throw new Error(`Cannot modify protected Lambda context field: ${String(key)}`);
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
this.currentContext = this.currentContext || {};
|
|
43
|
+
this.currentContext[key] = value;
|
|
44
|
+
}
|
|
45
|
+
run(context, fn) {
|
|
46
|
+
this.currentContext = context;
|
|
47
|
+
try {
|
|
48
|
+
return fn();
|
|
35
49
|
}
|
|
50
|
+
finally {
|
|
51
|
+
this.currentContext = undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
class InvokeStoreMulti extends InvokeStoreBase {
|
|
56
|
+
als;
|
|
57
|
+
static async create() {
|
|
58
|
+
const instance = new InvokeStoreMulti();
|
|
59
|
+
const asyncHooks = await import('node:async_hooks');
|
|
60
|
+
instance.als = new asyncHooks.AsyncLocalStorage();
|
|
61
|
+
return instance;
|
|
36
62
|
}
|
|
37
|
-
|
|
38
|
-
return this.
|
|
63
|
+
getContext() {
|
|
64
|
+
return this.als.getStore();
|
|
39
65
|
}
|
|
40
|
-
|
|
41
|
-
return this.
|
|
66
|
+
hasContext() {
|
|
67
|
+
return this.als.getStore() !== undefined;
|
|
42
68
|
}
|
|
43
|
-
|
|
44
|
-
return this.
|
|
69
|
+
get(key) {
|
|
70
|
+
return this.als.getStore()?.[key];
|
|
45
71
|
}
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
set(key, value) {
|
|
73
|
+
if (this.isProtectedKey(key)) {
|
|
74
|
+
throw new Error(`Cannot modify protected Lambda context field: ${String(key)}`);
|
|
75
|
+
}
|
|
76
|
+
const store = this.als.getStore();
|
|
77
|
+
if (!store) {
|
|
78
|
+
throw new Error("No context available");
|
|
79
|
+
}
|
|
80
|
+
store[key] = value;
|
|
48
81
|
}
|
|
49
|
-
|
|
50
|
-
return
|
|
51
|
-
key === this.PROTECTED_KEYS.X_RAY_TRACE_ID);
|
|
82
|
+
run(context, fn) {
|
|
83
|
+
return this.als.run(context, fn);
|
|
52
84
|
}
|
|
53
85
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
instance =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
86
|
+
exports.InvokeStore = void 0;
|
|
87
|
+
(function (InvokeStore) {
|
|
88
|
+
let instance = null;
|
|
89
|
+
async function getInstanceAsync() {
|
|
90
|
+
if (!instance) {
|
|
91
|
+
instance = (async () => {
|
|
92
|
+
const isMulti = "AWS_LAMBDA_MAX_CONCURRENCY" in process.env;
|
|
93
|
+
const newInstance = isMulti
|
|
94
|
+
? await InvokeStoreMulti.create()
|
|
95
|
+
: new InvokeStoreSingle();
|
|
96
|
+
if (!NO_GLOBAL_AWS_LAMBDA && globalThis.awslambda?.InvokeStore) {
|
|
97
|
+
return globalThis.awslambda.InvokeStore;
|
|
98
|
+
}
|
|
99
|
+
else if (!NO_GLOBAL_AWS_LAMBDA && globalThis.awslambda) {
|
|
100
|
+
globalThis.awslambda.InvokeStore = newInstance;
|
|
101
|
+
return newInstance;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
return newInstance;
|
|
105
|
+
}
|
|
106
|
+
})();
|
|
107
|
+
}
|
|
108
|
+
return instance;
|
|
62
109
|
}
|
|
63
|
-
|
|
64
|
-
|
|
110
|
+
InvokeStore.getInstanceAsync = getInstanceAsync;
|
|
111
|
+
InvokeStore._testing = process.env.AWS_LAMBDA_BENCHMARK_MODE === "1"
|
|
112
|
+
? {
|
|
113
|
+
reset: () => {
|
|
114
|
+
instance = null;
|
|
115
|
+
if (globalThis.awslambda?.InvokeStore) {
|
|
116
|
+
delete globalThis.awslambda.InvokeStore;
|
|
117
|
+
}
|
|
118
|
+
globalThis.awslambda = {};
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
: undefined;
|
|
122
|
+
})(exports.InvokeStore || (exports.InvokeStore = {}));
|
|
65
123
|
|
|
66
|
-
exports.
|
|
124
|
+
exports.InvokeStoreBase = InvokeStoreBase;
|
|
@@ -1,64 +1,122 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
-
|
|
3
|
-
const noGlobalAwsLambda = process.env["AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA"] === "1" ||
|
|
4
|
-
process.env["AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA"] === "true";
|
|
5
|
-
if (!noGlobalAwsLambda) {
|
|
6
|
-
globalThis.awslambda = globalThis.awslambda || {};
|
|
7
|
-
}
|
|
8
1
|
const PROTECTED_KEYS = {
|
|
9
|
-
REQUEST_ID: Symbol("_AWS_LAMBDA_REQUEST_ID"),
|
|
10
|
-
X_RAY_TRACE_ID: Symbol("_AWS_LAMBDA_X_RAY_TRACE_ID"),
|
|
11
|
-
TENANT_ID: Symbol("_AWS_LAMBDA_TENANT_ID"),
|
|
2
|
+
REQUEST_ID: Symbol.for("_AWS_LAMBDA_REQUEST_ID"),
|
|
3
|
+
X_RAY_TRACE_ID: Symbol.for("_AWS_LAMBDA_X_RAY_TRACE_ID"),
|
|
4
|
+
TENANT_ID: Symbol.for("_AWS_LAMBDA_TENANT_ID"),
|
|
12
5
|
};
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
const NO_GLOBAL_AWS_LAMBDA = ["true", "1"].includes(process.env?.AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA ?? "");
|
|
7
|
+
if (!NO_GLOBAL_AWS_LAMBDA) {
|
|
8
|
+
globalThis.awslambda = globalThis.awslambda || {};
|
|
9
|
+
}
|
|
10
|
+
class InvokeStoreBase {
|
|
15
11
|
static PROTECTED_KEYS = PROTECTED_KEYS;
|
|
16
|
-
|
|
17
|
-
return
|
|
12
|
+
isProtectedKey(key) {
|
|
13
|
+
return Object.values(PROTECTED_KEYS).includes(key);
|
|
14
|
+
}
|
|
15
|
+
getRequestId() {
|
|
16
|
+
return this.get(PROTECTED_KEYS.REQUEST_ID) ?? "-";
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
return this.
|
|
18
|
+
getXRayTraceId() {
|
|
19
|
+
return this.get(PROTECTED_KEYS.X_RAY_TRACE_ID);
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return context?.[key];
|
|
21
|
+
getTenantId() {
|
|
22
|
+
return this.get(PROTECTED_KEYS.TENANT_ID);
|
|
25
23
|
}
|
|
26
|
-
|
|
24
|
+
}
|
|
25
|
+
class InvokeStoreSingle extends InvokeStoreBase {
|
|
26
|
+
currentContext;
|
|
27
|
+
getContext() {
|
|
28
|
+
return this.currentContext;
|
|
29
|
+
}
|
|
30
|
+
hasContext() {
|
|
31
|
+
return this.currentContext !== undefined;
|
|
32
|
+
}
|
|
33
|
+
get(key) {
|
|
34
|
+
return this.currentContext?.[key];
|
|
35
|
+
}
|
|
36
|
+
set(key, value) {
|
|
27
37
|
if (this.isProtectedKey(key)) {
|
|
28
|
-
throw new Error(`Cannot modify protected Lambda context field`);
|
|
38
|
+
throw new Error(`Cannot modify protected Lambda context field: ${String(key)}`);
|
|
29
39
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
this.currentContext = this.currentContext || {};
|
|
41
|
+
this.currentContext[key] = value;
|
|
42
|
+
}
|
|
43
|
+
run(context, fn) {
|
|
44
|
+
this.currentContext = context;
|
|
45
|
+
try {
|
|
46
|
+
return fn();
|
|
33
47
|
}
|
|
48
|
+
finally {
|
|
49
|
+
this.currentContext = undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class InvokeStoreMulti extends InvokeStoreBase {
|
|
54
|
+
als;
|
|
55
|
+
static async create() {
|
|
56
|
+
const instance = new InvokeStoreMulti();
|
|
57
|
+
const asyncHooks = await import('node:async_hooks');
|
|
58
|
+
instance.als = new asyncHooks.AsyncLocalStorage();
|
|
59
|
+
return instance;
|
|
34
60
|
}
|
|
35
|
-
|
|
36
|
-
return this.
|
|
61
|
+
getContext() {
|
|
62
|
+
return this.als.getStore();
|
|
37
63
|
}
|
|
38
|
-
|
|
39
|
-
return this.
|
|
64
|
+
hasContext() {
|
|
65
|
+
return this.als.getStore() !== undefined;
|
|
40
66
|
}
|
|
41
|
-
|
|
42
|
-
return this.
|
|
67
|
+
get(key) {
|
|
68
|
+
return this.als.getStore()?.[key];
|
|
43
69
|
}
|
|
44
|
-
|
|
45
|
-
|
|
70
|
+
set(key, value) {
|
|
71
|
+
if (this.isProtectedKey(key)) {
|
|
72
|
+
throw new Error(`Cannot modify protected Lambda context field: ${String(key)}`);
|
|
73
|
+
}
|
|
74
|
+
const store = this.als.getStore();
|
|
75
|
+
if (!store) {
|
|
76
|
+
throw new Error("No context available");
|
|
77
|
+
}
|
|
78
|
+
store[key] = value;
|
|
46
79
|
}
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
key === this.PROTECTED_KEYS.X_RAY_TRACE_ID);
|
|
80
|
+
run(context, fn) {
|
|
81
|
+
return this.als.run(context, fn);
|
|
50
82
|
}
|
|
51
83
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
instance =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
84
|
+
var InvokeStore;
|
|
85
|
+
(function (InvokeStore) {
|
|
86
|
+
let instance = null;
|
|
87
|
+
async function getInstanceAsync() {
|
|
88
|
+
if (!instance) {
|
|
89
|
+
instance = (async () => {
|
|
90
|
+
const isMulti = "AWS_LAMBDA_MAX_CONCURRENCY" in process.env;
|
|
91
|
+
const newInstance = isMulti
|
|
92
|
+
? await InvokeStoreMulti.create()
|
|
93
|
+
: new InvokeStoreSingle();
|
|
94
|
+
if (!NO_GLOBAL_AWS_LAMBDA && globalThis.awslambda?.InvokeStore) {
|
|
95
|
+
return globalThis.awslambda.InvokeStore;
|
|
96
|
+
}
|
|
97
|
+
else if (!NO_GLOBAL_AWS_LAMBDA && globalThis.awslambda) {
|
|
98
|
+
globalThis.awslambda.InvokeStore = newInstance;
|
|
99
|
+
return newInstance;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return newInstance;
|
|
103
|
+
}
|
|
104
|
+
})();
|
|
105
|
+
}
|
|
106
|
+
return instance;
|
|
60
107
|
}
|
|
61
|
-
|
|
62
|
-
|
|
108
|
+
InvokeStore.getInstanceAsync = getInstanceAsync;
|
|
109
|
+
InvokeStore._testing = process.env.AWS_LAMBDA_BENCHMARK_MODE === "1"
|
|
110
|
+
? {
|
|
111
|
+
reset: () => {
|
|
112
|
+
instance = null;
|
|
113
|
+
if (globalThis.awslambda?.InvokeStore) {
|
|
114
|
+
delete globalThis.awslambda.InvokeStore;
|
|
115
|
+
}
|
|
116
|
+
globalThis.awslambda = {};
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
: undefined;
|
|
120
|
+
})(InvokeStore || (InvokeStore = {}));
|
|
63
121
|
|
|
64
|
-
export { InvokeStore };
|
|
122
|
+
export { InvokeStore, InvokeStoreBase };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|