{"id":14957648,"url":"https://github.com/moesif/moesif-aws-lambda-nodejs","last_synced_at":"2025-11-11T20:07:42.459Z","repository":{"id":44168905,"uuid":"101356146","full_name":"Moesif/moesif-aws-lambda-nodejs","owner":"Moesif","description":"Moesif AWS Lambda middleware for Node.js, for API Monitoring, Analytics, and Monetization.","archived":false,"fork":false,"pushed_at":"2024-10-11T16:30:45.000Z","size":307,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-12T16:03:05.875Z","etag":null,"topics":["analytics","api-analytics","api-gateway","api-logs","api-management","api-monetization","api-monitoring","aws-lambda-node","logger","logging","monitoring","nodejs-lambda","observability","usage-based-billing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Moesif.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-25T02:14:09.000Z","updated_at":"2024-10-07T14:01:09.000Z","dependencies_parsed_at":"2023-12-21T22:24:14.313Z","dependency_job_id":"7a1d56f2-3cff-4428-bb77-0ed5bb320b6b","html_url":"https://github.com/Moesif/moesif-aws-lambda-nodejs","commit_stats":{"total_commits":58,"total_committers":8,"mean_commits":7.25,"dds":0.6206896551724138,"last_synced_commit":"986967e201974caa64d6cea77b907c78f583c3ad"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moesif%2Fmoesif-aws-lambda-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moesif%2Fmoesif-aws-lambda-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moesif%2Fmoesif-aws-lambda-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moesif%2Fmoesif-aws-lambda-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Moesif","download_url":"https://codeload.github.com/Moesif/moesif-aws-lambda-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224305847,"owners_count":17289446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","api-analytics","api-gateway","api-logs","api-management","api-monetization","api-monitoring","aws-lambda-node","logger","logging","monitoring","nodejs-lambda","observability","usage-based-billing"],"created_at":"2024-09-24T13:15:17.344Z","updated_at":"2025-11-11T20:07:37.425Z","avatar_url":"https://github.com/Moesif.png","language":"JavaScript","readme":"# Moesif AWS Lambda Middleware for Node.js documentation\nby [Moesif](https://moesif.com), the [API analytics](https://www.moesif.com/features/api-analytics) and [API monetization](https://www.moesif.com/solutions/metered-api-billing) platform.\n\n[![NPM](https://nodei.co/npm/moesif-aws-lambda-nodejs.png?compact=true\u0026stars=true)](https://nodei.co/npm/moesif-aws-lambda/)\n\n[![Built For][ico-built-for]][link-built-for]\n[![Software License][ico-license]][link-license]\n[![Source Code][ico-source]][link-source]\n\nWith Moesif Node.js middleware for AWS Lambda, you can automatically log API calls \nand send them to [Moesif](https://www.moesif.com) for API analytics and monitoring.\nThis middleware allows you to integrate Moesif's API analytics and \nAPI monetization features into your Node.js applications with minimal configuration.\n\n\u003e If you're new to Moesif, see [our Getting Started](https://www.moesif.com/docs/) resources to quickly get up and running.\n\n## Who This Middleware is For\n\nWe've designed Moesif Node.js middleware for AWS Lambda for APIs that you host \non AWS Lambda using Amazon API Gateway or Application Load Balancer\nas a trigger. The middleware works with REST APIs, [GraphQL APIs](https://www.moesif.com/features/graphql-analytics) \n([such as with `apollo-server-lambda`](https://github.com/Moesif/moesif-aws-lambda-apollo-example)), and more.\n\nIf you're running a Node.js framework like Express.js on AWS Lambda and prefer to not have any \nAWS-specific dependencies, Moesif also has a \u003ca href=\"https://www.moesif.com/docs/server-integration/nodejs/\"\u003eNode.js middleware\u003c/a\u003e available. The Node.js middleware supports all Node.js frameworks, including Express.js. \nHowever, the Node.js middleware doesn't capture Lambda-specific context like trade ID.\n\n## Prerequisites\nBefore using this middleware, make sure you have the following:\n\n- [An active Moesif account](https://moesif.com/wrap)\n- [A Moesif Application ID](#get-your-moesif-application-id)\n\n### Get Your Moesif Application ID\nAfter you log into [Moesif Portal](https://www.moesif.com/wrap), you can get your Moesif Application ID during the onboarding steps. You can always access the Application ID any time by following these steps from Moesif Portal after logging in:\n\n1. Select the account icon to bring up the settings menu.\n2. Select **Installation** or **API Keys**.\n3. Copy your Moesif Application ID from the **Collector Application ID** field.\n\u003cimg class=\"lazyload blur-up\" src=\"images/app_id.png\" width=\"700\" alt=\"Accessing the settings menu in Moesif Portal\"\u003e\n\n## Install the middleware\nIn your project directory, install the middleware as a project dependency:\n\n```shell\nnpm install --save moesif-aws-lambda\n```\n\n## Configure the Middleware\nSee the available [configuration options](#configuration-options) to learn how to configure the middleware for your use case. \n\n## How to use\n\n### 1. Import the Module and Initialize\n\n\n```javascript\n// Import Modules\n'use strict'\nconst moesif = require('moesif-aws-lambda');\n\nconst moesifOptions = {\n    applicationId: 'YOUR_MOESIF_APPLICATION_ID',\n\n    identifyUser: function (event, context) {\n        return event.requestContext.identity.cognitoIdentityId\n    },\n    identifyCompany: function (event, context) {\n        return '5678'\n    }\n};\n\nexports.handler = function (event, context, callback) {\n    callback(null, {\n        statusCode: '200',\n        body: JSON.stringify({key: 'hello world'}),\n        headers: {\n            'Content-Type': 'application/json',\n        },\n    });\n};\n\nexports.handler = moesif(moesifOptions, exports.handler);\n```\n\nReplace *`YOUR_MOESIF_APPLICATION_ID`* with [your Moesif Application ID](#get-your-moesif-application-id).\n\nDepends on the version of Node.js, you can also import directly:\n\n```javascript\nimport moesif from 'moesif-aws-lambda'\n```\n\nIf you are using ECMAScript modules (ES modules) or later version of ES modules, try the following method:\n\n```javascript\nconst moesifImportWrapper = await import('moesif-aws-lambda');\nconst moesif = moesifImportWrapper.default;\n```\n\n### 2. Enter Your Moesif Application ID\nThe 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). \n\nFor instructions on how to obtain your Application ID, see [Get your Moesif Application ID](#get-your-moesif-application-id).\n\nYou can hardcode your Moesif Application ID value in `applicationId`. But we highly recommend that you use a more secure option like environment variables to store your Application ID. If you set the environment variable as `MOESIF_APPLICATION_ID`, Moesif automatically picks it up without you having to explicitly specify it in the `applicationId` key.\n\n### 3. Call Your API\n\nFinally, grab the URL to your API Gateway or Application Load Balancer and make some HTTP requests using a tool like Postman or cURL.\n\n\u003e In order for your events to log to Moesif, you must test using the Amazon API Gateway trigger. Do not invoke your Lambda directly using AWS Console as the payload won't contain a valid HTTP payload.\n\n## Troubleshoot\nFor a general troubleshooting guide that can help you solve common problems, see [Server Troubleshooting Guide](https://www.moesif.com/docs/troubleshooting/server-troubleshooting-guide/).\n\nOther troubleshooting supports:\n\n- [FAQ](https://www.moesif.com/docs/faq/)\n- [Moesif support email](mailto:support@moesif.com)\n\n\n## Repository Structure\n\n```\n.\n├── app.js\n├── images/\n├── lib/\n├── LICENSE\n├── package.json\n├── package-lock.json\n├── README.md\n└── tests/\n```\n\nThese are the most important files:\n\n- **`lib/index.js`**: the middleware library\n- **`app.js`**: sample AWS Lambda function using the middleware\n\n\n## Configuration Options\nThe following sections describe the available configuration options for this middleware. You can set these options in the Moesif initialization options object. See [the sample AWS Lambda middleware function code](https://github.com/Moesif/moesif-aws-lambda-nodejs/blob/89c384621f8ae5fcee9166d798feb1e3115459ae/app.js#L15) for an example.\n\n### `logBody`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Default\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eBoolean\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003etrue\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\nWhether to log request and response body to Moesif.\n\n### `identifyUser`\n\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(event, context)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eString\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA function that takes AWS lambda `event` and `context` objects as arguments\nand returns a user ID. This allows Moesif to attribute API requests to individual unique users\nso you can understand who is calling your API. You can use this simultaneously with [`identifyCompany`](#identifycompany)\nto track both individual customers and the companies they are a part of.\n\n\n```javascript\noptions.identifyUser = function (event, context) {\n  // your code here, must return a string\n  return event.requestContext.identity.cognitoIdentityId\n}\n```\n\n### `identifyCompany`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(event, context)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eString\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA function that takes AWS lambda `event` and `context` objects as arguments\nand returns a company ID. If you have a B2B business, this allows Moesif to attribute\nAPI requests to specific companies or organizations so you can understand which accounts are\ncalling your API. You can use this simultaneously with [`identifyUser`](#identifyuser) to track both\nindividual customers and the companies they are a part of.\n\n\n```javascript\noptions.identifyCompany = function (event, context) {\n  // your code here, must return a string\n  return '5678'\n}\n```\n\n### `getSessionToken`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(event, context)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eString\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA function that takes AWS lambda `event` and `context` objects as arguments and returns a\nsession token such as an API key.\n\n\n```javascript\noptions.getSessionToken = function (event, context) {\n  // your code here, must return a string.\n  return event.headers['Authorization'];\n}\n```\n\n### `getApiVersion`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(event, context)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eString\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA function that takes AWS lambda `event` and `context` objects as arguments and\nreturns a string to tag requests with a specific version of your API.\n\n```javascript\noptions.getApiVersion = function (event, context) {\n  // your code here. must return a string.\n  return '1.0.5'\n}\n```\n\n### `getMetadata`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(event, context)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eObject\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA function that takes AWS lambda `event` and `context` objects as arguments and returns an object. \n\nThis function allows you\nto add custom metadata that Moesif can associate with the request. The metadata must be a simple JavaScript object that can be converted to JSON. \n\nFor example, you may want to save a virtual machine instance ID, a trace ID, or a tenant ID with the request.\n\n\n```javascript\noptions.getMetadata = function (event, context)  {\n  // your code here:\n  return {\n    foo: 'custom data',\n    bar: 'another custom data'\n  };\n}\n```\n\n### `skip`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(event, context)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eBoolean\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA function that takes AWS lambda `event` and `context` objects as arguments and returns `true`\nif you want to skip the event. Skipping an event means Moesif doesn't log the event.\n\nThe following example skips requests to the root path `/`:\n\n```javascript\noptions.skip = function (event, context) {\n  // your code here. must return a boolean.\n  if (event.path === '/') {\n    // Skip probes to home page.\n    return true;\n  }\n  return false\n}\n```\n\n### `maskContent`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(MoesifEventModel)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eMoesifEventModel\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nA function that takes the final Moesif event model, rather than the AWS lambda event or context objects, as an\nargument before the middleware sends the event model object to Moesif. \n\nWith `maskContent`, you can make modifications to headers or body such as\nremoving certain header or body fields.\n\n```javascript\noptions.maskContent = function(moesifEvent) {\n  // remove any field that you don't want to be sent to Moesif.\n  return moesifEvent;\n}\n ```\n\nMoesif's event model format looks like this:\n\n```json\n{\n  \"request\": {\n    \"time\": \"2019-08-08T04:45:42.914\",\n    \"uri\": \"https://api.acmeinc.com/items/83738/reviews/\",\n    \"verb\": \"POST\",\n    \"api_version\": \"1.1.0\",\n    \"ip_address\": \"61.48.220.123\",\n    \"headers\": {\n      \"Host\": \"api.acmeinc.com\",\n      \"Accept\": \"*/*\",\n      \"Connection\": \"Keep-Alive\",\n      \"Content-Type\": \"application/json\",\n      \"Content-Length\": \"126\",\n      \"Accept-Encoding\": \"gzip\"\n    },\n    \"body\": {\n      \"items\": [\n        {\n          \"direction_type\": 1,\n          \"item_id\": \"fwdsfrf\",\n          \"liked\": false\n        },\n        {\n          \"direction_type\": 2,\n          \"item_id\": \"d43d3f\",\n          \"liked\": true\n        }\n      ]\n    }\n  },\n  \"response\": {\n    \"time\": \"2019-08-08T04:45:42.924\",\n    \"status\": 500,\n    \"headers\": {\n      \"Vary\": \"Accept-Encoding\",\n      \"Pragma\": \"no-cache\",\n      \"Expires\": \"-1\",\n      \"Content-Type\": \"application/json; charset=utf-8\",\n      \"Cache-Control\": \"no-cache\"\n    },\n    \"body\": {\n      \"Error\": \"InvalidArgumentException\",\n      \"Message\": \"Missing field location\"\n    }\n  },\n  \"user_id\": \"my_user_id\",\n  \"company_id\": \"my_company_id\",\n  \"session_token\":\"end_user_session_token\",\n  \"tags\": \"tag1, tag2\"\n}\n```\n\nFor more information about the different fields of Moesif's event model,\nsee the following table or the [Moesif Node.js API documentation](https://www.moesif.com/docs/api?javascript).\n\nName | Required | Description\n--------- | -------- | -----------\n`request` | Yes | The object that specifies the API request.\n`request.time`| Yes | Timestamp for the request in ISO 8601 format.\n`request.uri`| Yes | Full URI such as `https://api.com/?query=string` including host, query string, and so on.\n`request.verb`| Yes | The HTTP method—for example, `GET` and `POST`.\n`request.api_version`| No | API Version you want to tag this request with such as `1.0.0`.\n`request.ip_address`| No | IP address of the client. If not set, Moesif uses the IP address of your logging API calls.\n`request.headers`| Yes | Headers of the  request as a `Map\u003cstring, string\u003e` object. Multiple headers with the same key name should be combined together such that the values are joined by a comma. For more information, see [HTTP Header Protocol on w3.org](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2)\n`request.body`| No | Body of the request in JSON format or base64 encoded binary data. To specify the transfer encoding, use `request.transfer_encoding`.\n`request.transfer_encoding`| No | A string that specifies the transfer encoding of the request body sent to Moesif. If not specified, Moesif assumes the request body assumed to be JSON or text. Only supported value is `base64` for sending binary data like protocol buffers.\n||\n`response` | No | The object that specifies the `response message`. If not set, it implies a null response such as a timeout.\n`response.time`| Yes | Timestamp for the response in ISO 8601 format.\n`response.status`| Yes | HTTP response status code number such as `200 OK` or `500 Internal Server Error`.\n`response.ip_address`| No | IP address of the responding server.\n`response.headers`| Yes | Headers of the response as a `Map\u003cstring, string\u003e` object. Multiple headers with the same key name should be combined together such that the values are joined by a comma. For more information, see [HTTP Header Protocol on w3.org](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2)\n`response.body`| No | Body of the response in JSON format or base64 encoded binary data. To specify the transfer encoding, use `response.transfer_encoding`\n`response.transfer_encoding`| No | A string that specifies the transfer encoding of the request body sent to Moesif. If not specified, Moesif assumes the body to be JSON or text. Only supported value is `base64` for sending binary data like protocol buffers.\n||\n`session_token` | Recommended | The end user session token such as a JWT or API key, which may or may not be temporary. Moesif automatically detects the session token if not set.\n`user_id` | Recommended | Identifies this API call to a permanent user ID.\n`metadata` | No | A JSON Object consisting of any custom metadata to be stored with this event.\n\n\n### `debug`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Default\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eBoolean\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eundefined\u003c/code\u003e\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nSet to `true` to print debug logs if you're having integration issues.\n\n## Capture Outgoing API Calls\n\nIf you want to capture all outgoing API calls from your Node.js app to third parties like\nStripe or to your own dependencies, call `startCaptureOutgoing()` to start capturing.\n\n```javascript\nconst moesif = require('moesif-aws-lambda');\nvar moesifMiddleware = moesif(options);\nmoesifMiddleware.startCaptureOutgoing();\n```\n\nThe same set of options also applies to outgoing API calls, with a few key differences:\n\nThere are several configuration option functions that take request and response object as arguments. The request and response objects passed into those functions\nare not Express or Node.js request or response objects when the request is outgoing, but Moesif mocks\nsome of the fields for convenience.\n\nOnly a subset of the Node.js request or response fields are available, specifically the following:\n\n### `mo_mocked`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Description\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eBoolean\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    Set to \u003ccode\u003etrue\u003c/code\u003e if it is a mocked request or response object, for example, outgoing API call.\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### `headers`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Description\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eObject\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    A mapping of header names to header values. Case sensitive.\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### `url`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Description\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eString\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    The full request URL.\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\n### `method`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Description\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eString\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    The HTTP method such as \u003ccode\u003eGET\u003c/code\u003e or \u003ccode\u003ePOST\u003c/code\u003e.\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### `statusCode`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Description\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eNumber\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    The HTTP response status code number.\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### `getHeader`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Description\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(String)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eString\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    Reads out a header on the request. Name is case insensitive\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### `get`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Parameters\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Return type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Description\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    Function\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003e(String)\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    \u003ccode\u003eString\u003c/code\u003e\n   \u003c/td\u003e\n   \u003ctd\u003e\n    Reads out a header on the request. Name is case insensitive\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### `body`\n\u003ctable\u003e\n  \u003ctr\u003e\n   \u003cth scope=\"col\"\u003e\n    Data type\n   \u003c/th\u003e\n   \u003cth scope=\"col\"\u003e\n    Description\n   \u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n   \u003ctd\u003e\n    JSON object\n   \u003c/td\u003e\n   \u003ctd\u003e\n    The request body as sent to Moesif.\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Examples\nSee the [example AWS Lambda function](https://github.com/Moesif/moesif-aws-lambda-nodejs/blob/master/app.js) that uses this middleware.\n\nThe following examples demonstrate how to add and update customer information.\n\n### Update a Single User\n\nTo create or update a [user](https://www.moesif.com/docs/getting-started/users/) profile in Moesif, use the `updateUser()` function.\n\n```javascript\nvar moesifMiddleware = moesif(options);\n\n// Only userId is required.\n// Campaign object is optional, but useful if you want to track ROI of acquisition channels\n// See https://www.moesif.com/docs/api#users for campaign schema\n// metadata can be any custom object\nvar user = {\n  userId: '12345',\n  companyId: '67890', // If set, associate user with a company object\n  campaign: {\n    utmSource: 'google',\n    utmMedium: 'cpc',\n    utmCampaign: 'adwords',\n    utmTerm: 'api+tooling',\n    utmContent: 'landing'\n  },\n  metadata: {\n    email: 'john@acmeinc.com',\n    firstName: 'John',\n    lastName: 'Doe',\n    title: 'Software Engineer',\n    salesInfo: {\n        stage: 'Customer',\n        lifetimeValue: 24000,\n        accountOwner: 'mary@contoso.com'\n    }\n  }\n};\n\nmoesifMiddleware.updateUser(user, callback);\n```\n\nThe `metadata` field can contain any customer demographic or other info you want to store. Moesif only requires the `userId` field.\n\nThis method is a convenient helper that calls the Moesif API library. For more information, see the function documentation in [Moesif Node.js API reference](https://www.moesif.com/docs/api?javascript--nodejs#update-a-user).\n\n### Update Users in Batch\nTo update a list of [users](https://www.moesif.com/docs/getting-started/users/) in one batch, use the `updateUsersBatch()` function.\n\n```javascript\nvar moesifMiddleware = moesif(options);\n\n// Only userId is required.\n// Campaign object is optional, but useful if you want to track ROI of acquisition channels\n// See https://www.moesif.com/docs/api#users for campaign schema\n//\n// Define the users. \nvar user = {\n  userId: '12345',\n  companyId: '67890', // If set, associate user with a company object\n  campaign: {\n    utmSource: 'google',\n    utmMedium: 'cpc',\n    utmCampaign: 'adwords',\n    utmTerm: 'api+tooling',\n    utmContent: 'landing'\n  },\n  // Metadata can be any custom object\n  metadata: {\n    email: 'john@acmeinc.com',\n    firstName: 'John',\n    lastName: 'Doe',\n    title: 'Software Engineer',\n    salesInfo: {\n        stage: 'Customer',\n        lifetimeValue: 24000,\n        accountOwner: 'mary@contoso.com'\n    }\n  }\n};\n\n// Put the users you inside an array.\nvar users = [user]\n\n// Call the function with the list of users.\nmoesifMiddleware.updateUsersBatch(users, callback);\n```\n\nThe `metadata` field can contain any customer demographic or other info you want to store. MOesif only requires the `userId` field.\n\nThis method is a convenient helper that calls the Moesif API library. For more information, see the function documentation in [Moesif Node.js API reference](https://www.moesif.com/docs/api?javascript--nodejs#update-users-in-batch).\n\n### Update a Single Company\nTo update a single [company](https://www.moesif.com/docs/getting-started/companies/), use the `updateCompany()` function.\n\n```javascript\nvar moesifMiddleware = moesif(options);\n\n// Only companyId is required.\n// Campaign object is optional, but useful if you want to track ROI of acquisition channels\n// See https://www.moesif.com/docs/api#update-a-company for campaign schema\n// metadata can be any custom object\nvar company = {\n  companyId: '67890',\n  companyDomain: 'acmeinc.com', // If domain is set, Moesif will enrich your profiles with publicly available info\n  campaign: {\n    utmSource: 'google',\n    utmMedium: 'cpc',\n    utmCampaign: 'adwords',\n    utmTerm: 'api+tooling',\n    utmContent: 'landing'\n  },\n  metadata: {\n    orgName: 'Acme, Inc',\n    planName: 'Free Plan',\n    dealStage: 'Lead',\n    mrr: 24000,\n    demographics: {\n      alexaRanking: 500000,\n      employeeCount: 47\n    }\n  }\n};\n\nmoesifMiddleware.updateCompany(company, callback);\n```\n\nThe `metadata` field can contain any company demographic or other information you want to store. Moesif only requires the `companyId` field.\n\nThis method is a convenient helper that calls the Moesif API library. For more information, see the function documentation in [Moesif Node.js API reference](https://www.moesif.com/docs/api?javascript--nodejs#update-a-company).\n\n### Update Companies in Batch\nTo update a list of [companies](https://www.moesif.com/docs/getting-started/companies/) in one batch, use the `updateCompaniesBatch()` function.\n\n```javascript\nvar moesifMiddleware = moesif(options);\n\n// Only companyId is required.\n// Campaign object is optional, but useful if you want to track ROI of acquisition channels\n// See https://www.moesif.com/docs/api#update-a-company for campaign schema\n//\n// Define your companies.\nvar company = {\n  companyId: '67890',\n  companyDomain: 'acmeinc.com', // If domain is set, Moesif will enrich your profiles with publicly available info\n  campaign: {\n    utmSource: 'google',\n    utmMedium: 'cpc',\n    utmCampaign: 'adwords',\n    utmTerm: 'api+tooling',\n    utmContent: 'landing'\n  },\n  // Metadata can be any custom object\n  metadata: {\n    orgName: 'Acme, Inc',\n    planName: 'Free Plan',\n    dealStage: 'Lead',\n    mrr: 24000,\n    demographics: {\n      alexaRanking: 500000,\n      employeeCount: 47\n    }\n  }\n};\n\n// Put the companies inside an array.\nvar companies = [company]\n\n// Call the function with the list of companies.\nmoesifMiddleware.updateCompaniesBatch(companies, callback);\n```\n\nThe `metadata` field can contain any company demographic or other information you want to store. Moesif only requires the `companyId` field.\n\nThis method is a convenient helper that calls the Moesif API library. For more information, see the function documentation in [Moesif Node.js API reference](https://www.moesif.com/docs/api?javascript--nodejs#update-companies-in-batch).\n\n## Additional Documentation\nFor more information and examples, see the following:\n\n- __[REST API Example](https://github.com/Moesif/moesif-aws-lambda-node-js-example)__: an AWS Lambda REST API built with Express.js.\n- __[Apollo GraphQL Example](https://github.com/Moesif/moesif-aws-lambda-apollo-example)__: an AWS Lambda GraphQL API built with [Apollo](https://www.apollographql.com/).\n- __[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/).\n\n\n\n## How to Get Help\nIf 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).\n\n## Explore Other Integrations\n\nExplore other integration options from Moesif:\n\n- [Server integration options documentation](https://www.moesif.com/docs/server-integration//)\n- [Client integration options documentation](https://www.moesif.com/docs/client-integration/)\n\n[ico-built-for]: https://img.shields.io/badge/built%20for-aws%20lambda-blue.svg\n[ico-license]: https://img.shields.io/badge/License-Apache%202.0-green.svg\n[ico-source]: https://img.shields.io/github/last-commit/moesif/moesif-aws-lambda-nodejs.svg?style=social\n\n[link-built-for]: https://aws.amazon.com/lambda/\n[link-license]: https://raw.githubusercontent.com/Moesif/moesif-aws-lambda-nodejs/master/LICENSE\n[link-source]: https://github.com/moesif/moesif-aws-lambda-nodejs","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoesif%2Fmoesif-aws-lambda-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoesif%2Fmoesif-aws-lambda-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoesif%2Fmoesif-aws-lambda-nodejs/lists"}