You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-13Lines changed: 24 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,22 +7,22 @@ by [Moesif](https://moesif.com), the [API analytics](https://www.moesif.com/feat
7
7
[![Software License][ico-license]][link-license]
8
8
[![Source Code][ico-source]][link-source]
9
9
10
-
With Moesif Node.js middleware for AWS Lambda, you can automatically log API calls
10
+
With Moesif Node.js middleware for AWS Lambda, you can automatically log API calls
11
11
and send them to [Moesif](https://www.moesif.com) for API analytics and monitoring.
12
-
This middleware allows you to integrate Moesif's API analytics and
12
+
This middleware allows you to integrate Moesif's API analytics and
13
13
API monetization features into your Node.js applications with minimal configuration.
14
14
15
15
> If you're new to Moesif, see [our Getting Started](https://www.moesif.com/docs/) resources to quickly get up and running.
16
16
17
17
## Who This Middleware is For
18
18
19
-
We've designed Moesif Node.js middleware for AWS Lambda for APIs that you host
19
+
We've designed Moesif Node.js middleware for AWS Lambda for APIs that you host
20
20
on AWS Lambda using Amazon API Gateway or Application Load Balancer
21
-
as a trigger. The middleware works with REST APIs, [GraphQL APIs](https://www.moesif.com/features/graphql-analytics)
21
+
as a trigger. The middleware works with REST APIs, [GraphQL APIs](https://www.moesif.com/features/graphql-analytics)
22
22
([such as with `apollo-server-lambda`](https://github.com/Moesif/moesif-aws-lambda-apollo-example)), and more.
23
23
24
-
If you're running a Node.js framework like Express.js on AWS Lambda and prefer to not have any
25
-
AWS-specific dependencies, Moesif also has a <ahref="https://www.moesif.com/docs/server-integration/nodejs/">Node.js middleware</a> available. The Node.js middleware supports all Node.js frameworks, including Express.js.
24
+
If you're running a Node.js framework like Express.js on AWS Lambda and prefer to not have any
25
+
AWS-specific dependencies, Moesif also has a <ahref="https://www.moesif.com/docs/server-integration/nodejs/">Node.js middleware</a> available. The Node.js middleware supports all Node.js frameworks, including Express.js.
26
26
However, the Node.js middleware doesn't capture Lambda-specific context like trade ID.
The middleware expects your Moesif Application ID in [the `applicationId` key of the Moesif initialization options object](https://github.com/Moesif/moesif-aws-lambda-nodejs/blob/89c384621f8ae5fcee9166d798feb1e3115459ae/app.js#L13).
102
+
The middleware expects your Moesif Application ID in [the `applicationId` key of the Moesif initialization options object](https://github.com/Moesif/moesif-aws-lambda-nodejs/blob/89c384621f8ae5fcee9166d798feb1e3115459ae/app.js#L13).
103
103
104
104
For instructions on how to obtain your Application ID, see [Get your Moesif Application ID](#get-your-moesif-application-id).
105
105
@@ -343,10 +343,10 @@ options.getApiVersion = function (event, context) {
343
343
</tr>
344
344
</table>
345
345
346
-
A function that takes AWS lambda `event` and `context` objects as arguments and returns an object.
346
+
A function that takes AWS lambda `event` and `context` objects as arguments and returns an object.
347
347
348
348
This function allows you
349
-
to add custom metadata that Moesif can associate with the request. The metadata must be a simple JavaScript object that can be converted to JSON.
349
+
to add custom metadata that Moesif can associate with the request. The metadata must be a simple JavaScript object that can be converted to JSON.
350
350
351
351
For example, you may want to save a virtual machine instance ID, a trace ID, or a tenant ID with the request.
352
352
@@ -430,7 +430,7 @@ options.skip = function (event, context) {
430
430
</table>
431
431
432
432
A function that takes the final Moesif event model, rather than the AWS lambda event or context objects, as an
433
-
argument before the middleware sends the event model object to Moesif.
433
+
argument before the middleware sends the event model object to Moesif.
434
434
435
435
With `maskContent`, you can make modifications to headers or body such as
436
436
removing certain header or body fields.
@@ -807,7 +807,7 @@ var moesifMiddleware = moesif(options);
807
807
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
808
808
// See https://www.moesif.com/docs/api#users for campaign schema
809
809
//
810
-
// Define the users.
810
+
// Define the users.
811
811
var user = {
812
812
userId:'12345',
813
813
companyId:'67890', // If set, associate user with a company object
@@ -935,6 +935,17 @@ For more information and examples, see the following:
935
935
-__[Moesif, Middy, and Serverless Example](https://github.com/Moesif/moesif-middy-serverless-example)__: an example showcasing how to use this middleware with [Middy](https://middy.js.org/) and [Serverless Framework](https://serverless.com/).
936
936
937
937
938
+
## Note about AWS Cold Start and Governance Rules
939
+
940
+
The `moesif-aws-lambda-nodejs` SDK fetches governance configuration from Moesif (for example, rules on which users or companies to block) and caches it in the Lambda execution environment’s memory.
941
+
942
+
For warm invocations (where the Lambda execution environment is already initialized), this in-memory cache works as expected.
943
+
944
+
On cold starts (when a new execution environment is initialized), there can be a short window before the configuration is fetched and the cache is populated. During this startup window, the SDK loads configuration asynchronously in the background, so governance decisions (like blocking) may not apply immediately.
945
+
946
+
In typical production APIs, regular traffic keeps functions warm, so the likelihood of requests slipping through this initial window is small.
947
+
948
+
In isolated tests or very low-traffic scenarios, the execution environment may be recycled and the cache cleared, recreating the short window until configuration is reloaded.
938
949
939
950
## How to Get Help
940
951
If you face any issues using this middleware, try the [troubheshooting guidelines](#troubleshoot). For further assistance, reach out to our [support team](mailto:support@moesif.com).
@@ -952,4 +963,4 @@ Explore other integration options from Moesif:
0 commit comments