moesif-aws-lambda


Namemoesif-aws-lambda JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://www.moesif.com/docs/server-integration/aws-lambda-python/
SummaryMoesif Middleware to automatically log API calls from AWS Lambda functions
upload_time2023-11-02 06:51:06
maintainer
docs_urlNone
authorMoesif, Inc
requires_python
licenseApache Software License
keywords moesif aws serverless api gateway lambda debug logging trace analytics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Moesif AWS Lambda Middleware

[![Built For][ico-built-for]][link-built-for]
[![Software License][ico-license]][link-license]
[![Source Code][ico-source]][link-source]

Middleware (Python) to automatically log API calls from AWS Lambda functions
and sends to [Moesif](https://www.moesif.com) for API analytics and log analysis. 

Designed for APIs that are hosted on AWS Lambda using Amazon API Gateway or Application Load Balancer
as a trigger.

This middleware expects the
[Lambda proxy integration type.](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-set-up-lambda-proxy-integration-on-proxy-resource)
If you're using AWS Lambda with API Gateway, you are most likely using the proxy integration type.

## How to install

```shell
pip install moesif_aws_lambda
```

## How to use

### 1. Add middleware to your Lambda application.

```python
from moesif_aws_lambda.middleware import MoesifLogger

moesif_options = {
    'LOG_BODY': True
}

@MoesifLogger(moesif_options)
def lambda_handler(event, context):
    return {
        'statusCode': 200,
        'isBase64Encoded': False,
        'body': {
            'msg': 'Hello from Lambda!'
        },
        'headers': {
            'Content-Type': 'application/json'
        }
    }
```

### 2. Set MOESIF_APPLICATION_ID environment variable 

Add a new environment variable with the name `MOESIF_APPLICATION_ID` and the value being your Moesif application id,
which can be found in the [_Moesif Portal_](https://www.moesif.com/).
After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps. 

You can always find your Moesif Application Id at any time by logging 
into the [_Moesif Portal_](https://www.moesif.com/), click on the top right menu,
 and then clicking _Installation_.

### 3. Trigger your API
Grab the URL to your API Gateway or LB and make some calls using a tool like Postman or CURL. 

> In order for your event 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.  

## Repo file structure

- `moesif_aws_lambda/middleware.py` the middleware library
- `lambda_function.py` sample AWS Lambda function using the middleware

## Optional: Capturing outgoing API calls
If you want to capture all outgoing API calls from your Python Lambda function to third parties like
Stripe or to your own dependencies, call `start_capture_outgoing()` to start capturing. This mechanism works by 
patching the [Requests](https://requests.readthedocs.io/en/master/) 

```python
from moesif_aws_lambda.middleware import *
start_capture_outgoing(moesif_options) # moesif_options are the configuration options.
```

## Configuration options

### __`IDENTIFY_USER`__

Type: `(event, context) => String`

`IDENTIFY_USER` is a function that takes AWS lambda `event` and `context` objects as arguments
and returns a user_id. This enables Moesif to attribute API requests to individual unique users
so you can understand who calling your API. This can be used simultaneously with `IDENTIFY_COMPANY`
to track both individual customers and the companies their a part of.


```python
def identify_user(event, context):
  # your code here, must return a string
  return event["requestContext"]["identity"]["cognitoIdentityId"]
```

### __`IDENTIFY_COMPANY`__

Type: `(event, context) => String`

`IDENTIFY_COMPANY` is a function that takes AWS lambda `event` and `context` objects as arguments
and returns a company_id. If your business is B2B, this enables Moesif to attribute 
API requests to specific companies or organizations so you can understand which accounts are 
calling your API. This can be used simultaneously with `IDENTIFY_USER` to track both 
individual customers and the companies their a part of. 


```python
def identify_company(event, context):
  # your code here, must return a string
  return '7890'
}
```

### __`GET_SESSION_TOKEN`__

Type: `(event, context) => String`

`GET_SESSION_TOKEN` a function that takes AWS lambda `event` and `context` objects as arguments and returns a
session token (i.e. such as an API key).


```python
def get_session_token(event, context):
    # your code here, must return a string.
    return 'XXXXXXXXX'
```

### __`GET_API_VERSION`__

Type: `(event, context) => String`

`GET_API_VERSION` is a function that takes AWS lambda `event` and `context` objects as arguments and
returns a string to tag requests with a specific version of your API.


```python
def get_api_version(event, context):
  # your code here. must return a string.
  return '1.0.0'
```

### __`GET_METADATA`__

Type: `(event, context) => String`

`GET_METADATA` is a function that AWS lambda `event` and `context` objects as arguments and returns an object that allows you to add custom metadata that will be associated with the request. The metadata must be a simple python object that can be converted to JSON. For example, you may want to save a function_name, a trace_id, or request_context with the request.


```python
def get_metadata(event, context):
  # your code here:
  return {
        'trace_id': context.aws_request_id,
        'function_name': context.function_name,
        'request_context': event['requestContext']
    }
```

### __`SKIP`__

Type: `(event, context) => Boolean`

`SKIP` is a function that takes AWS lambda `event` and `context` objects as arguments and returns true
if the event should be skipped (i.e. not logged)
<br/>_The default is shown below and skips requests to the root path "/"._


```python
def should_skip(event, context):
    # your code here. must return a boolean.
    return "/" in event['path']
```

### __`MASK_EVENT_MODEL`__

Type: `MoesifEventModel => MoesifEventModel`

`MASK_EVENT_MODEL` is a function that takes the final Moesif event model (rather than the AWS lambda event/context objects) as an argument before being sent to Moesif. With maskContent, you can make modifications to headers or body such as removing certain header or body fields.

```python
def mask_event(eventmodel):
  # remove any field that you don't want to be sent to Moesif.
  return eventmodel
 ```

### __`DEBUG`__

Type: `Boolean`

Set to true to print debug logs if you're having integration issues. 

### __`LOG_BODY`__

Type: `Boolean`

`LOG_BODY` is default to true, set to false to remove logging request and response body to Moesif.

## Options for logging outgoing calls

The options below are applied to outgoing API calls. The request and response objects passed in are  [Requests](https://requests.readthedocs.io/en/master/user/advanced/#request-and-response-objects) request and [Response](https://requests.readthedocs.io/en/master/user/advanced/#request-and-response-objects) response objects.

### __`SKIP_OUTGOING`__
(optional) _(req, res) => boolean_, a function that takes a [Requests](https://requests.readthedocs.io/en/master/) request and response,
and returns true if you want to skip this particular event.

### __`IDENTIFY_USER_OUTGOING`__
(optional, but highly recommended) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the user id used by your system. While Moesif tries to identify users automatically,
but different frameworks and your implementation might be very different, it would be helpful and much more accurate to provide this function.

### __`IDENTIFY_COMPANY_OUTGOING`__
(optional) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the company id for this event.

### __`GET_METADATA_OUTGOING`__
(optional) _(req, res) => dictionary_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and
returns a dictionary (must be able to be encoded into JSON). This allows
to associate this event with custom metadata. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.

### __`GET_SESSION_TOKEN_OUTGOING`__
(optional) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.

### __`LOG_BODY_OUTGOING`__
(optional) _boolean_, default True, Set to False to remove logging request and response body.

## Update User

### Update A Single User
Create or update a user profile in Moesif.
The metadata field can be any customer demographic or other info you want to store.
Only the `user_id` field is required.
For details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-a-user).

```python
from moesif_aws_lambda.middleware import *

moesif_options = {
    'LOG_BODY': True,
    'DEBUG': True,
}

# Only user_id is required.
# Campaign object is optional, but useful if you want to track ROI of acquisition channels
# See https://www.moesif.com/docs/api#users for campaign schema
# metadata can be any custom object
user = {
  'user_id': '12345',
  'company_id': '67890', # If set, associate user with a company object
  'campaign': {
    'utm_source': 'google',
    'utm_medium': 'cpc',
    'utm_campaign': 'adwords',
    'utm_term': 'api+tooling',
    'utm_content': 'landing'
  },
  'metadata': {
    'email': 'john@acmeinc.com',
    'first_name': 'John',
    'last_name': 'Doe',
    'title': 'Software Engineer',
    'sales_info': {
        'stage': 'Customer',
        'lifetime_value': 24000,
        'account_owner': 'mary@contoso.com'
    },
  }
}

update_user(user, moesif_options)
```

### Update Users in Batch
Similar to update_user, but used to update a list of users in one batch.
Only the `user_id` field is required.
For details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-users-in-batch).

```python
from moesif_aws_lambda.middleware import *

moesif_options = {
    'LOG_BODY': True,
    'DEBUG': True,
}

userA = {
  'user_id': '12345',
  'company_id': '67890', # If set, associate user with a company object
  'metadata': {
    'email': 'john@acmeinc.com',
    'first_name': 'John',
    'last_name': 'Doe',
    'title': 'Software Engineer',
    'sales_info': {
        'stage': 'Customer',
        'lifetime_value': 24000,
        'account_owner': 'mary@contoso.com'
    },
  }
}

userB = {
  'user_id': '54321',
  'company_id': '67890', # If set, associate user with a company object
  'metadata': {
    'email': 'mary@acmeinc.com',
    'first_name': 'Mary',
    'last_name': 'Jane',
    'title': 'Software Engineer',
    'sales_info': {
        'stage': 'Customer',
        'lifetime_value': 48000,
        'account_owner': 'mary@contoso.com'
    },
  }
}
update_users_batch([userA, userB], moesif_options)
```

## Update Company

### Update A Single Company
Create or update a company profile in Moesif.
The metadata field can be any company demographic or other info you want to store.
Only the `company_id` field is required.
For details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-a-company).

```python
from moesif_aws_lambda.middleware import *

moesif_options = {
    'LOG_BODY': True,
    'DEBUG': True,
}

# Only company_id is required.
# Campaign object is optional, but useful if you want to track ROI of acquisition channels
# See https://www.moesif.com/docs/api#update-a-company for campaign schema
# metadata can be any custom object
company = {
  'company_id': '67890',
  'company_domain': 'acmeinc.com', # If domain is set, Moesif will enrich your profiles with publicly available info
  'campaign': {
    'utm_source': 'google',
    'utm_medium': 'cpc',
    'utm_campaign': 'adwords',
    'utm_term': 'api+tooling',
    'utm_content': 'landing'
  },
  'metadata': {
    'org_name': 'Acme, Inc',
    'plan_name': 'Free',
    'deal_stage': 'Lead',
    'mrr': 24000,
    'demographics': {
        'alexa_ranking': 500000,
        'employee_count': 47
    },
  }
}

update_company(company, moesif_options)
```

### Update Companies in Batch
Similar to update_company, but used to update a list of companies in one batch.
Only the `company_id` field is required.
For details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-companies-in-batch).

```python
from moesif_aws_lambda.middleware import *

moesif_options = {
    'LOG_BODY': True,
    'DEBUG': True,
}

companyA = {
  'company_id': '67890',
  'company_domain': 'acmeinc.com', # If domain is set, Moesif will enrich your profiles with publicly available info
  'metadata': {
    'org_name': 'Acme, Inc',
    'plan_name': 'Free',
    'deal_stage': 'Lead',
    'mrr': 24000,
    'demographics': {
        'alexa_ranking': 500000,
        'employee_count': 47
    },
  }
}

companyB = {
  'company_id': '09876',
  'company_domain': 'contoso.com', # If domain is set, Moesif will enrich your profiles with publicly available info
  'metadata': {
    'org_name': 'Contoso, Inc',
    'plan_name': 'Free',
    'deal_stage': 'Lead',
    'mrr': 48000,
    'demographics': {
        'alexa_ranking': 500000,
        'employee_count': 53
    },
  }
}

update_companies_batch([companyA, companyB], moesif_options)
```

## Examples

- [A complete example is available on GitHub](https://github.com/Moesif/moesif-aws-lambda-python-example).

## Other integrations

To view more documentation on integration options, please visit __[the Integration Options Documentation](https://www.moesif.com/docs/getting-started/integration-options/).__

[ico-built-for]: https://img.shields.io/badge/built%20for-aws%20lambda-blue.svg
[ico-license]: https://img.shields.io/badge/License-Apache%202.0-green.svg
[ico-source]: https://img.shields.io/github/last-commit/moesif/moesif-aws-lambda-python.svg?style=social

[link-built-for]: https://aws.amazon.com/lambda/
[link-license]: https://raw.githubusercontent.com/Moesif/moesif-aws-lambda-python/master/LICENSE
[link-source]: https://github.com/moesif/moesif-aws-lambda-python

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.moesif.com/docs/server-integration/aws-lambda-python/",
    "name": "moesif-aws-lambda",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "moesif aws serverless api gateway lambda debug logging trace analytics",
    "author": "Moesif, Inc",
    "author_email": "keyur@moesif.com",
    "download_url": "https://files.pythonhosted.org/packages/3e/13/b089a0a618f6dd258262266966ed5f3f6b51c2b9ec8888e7989659055cee/moesif_aws_lambda-1.2.1.tar.gz",
    "platform": null,
    "description": "# Moesif AWS Lambda Middleware\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\nMiddleware (Python) to automatically log API calls from AWS Lambda functions\nand sends to [Moesif](https://www.moesif.com) for API analytics and log analysis. \n\nDesigned for APIs that are hosted on AWS Lambda using Amazon API Gateway or Application Load Balancer\nas a trigger.\n\nThis middleware expects the\n[Lambda proxy integration type.](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-set-up-lambda-proxy-integration-on-proxy-resource)\nIf you're using AWS Lambda with API Gateway, you are most likely using the proxy integration type.\n\n## How to install\n\n```shell\npip install moesif_aws_lambda\n```\n\n## How to use\n\n### 1. Add middleware to your Lambda application.\n\n```python\nfrom moesif_aws_lambda.middleware import MoesifLogger\n\nmoesif_options = {\n    'LOG_BODY': True\n}\n\n@MoesifLogger(moesif_options)\ndef lambda_handler(event, context):\n    return {\n        'statusCode': 200,\n        'isBase64Encoded': False,\n        'body': {\n            'msg': 'Hello from Lambda!'\n        },\n        'headers': {\n            'Content-Type': 'application/json'\n        }\n    }\n```\n\n### 2. Set MOESIF_APPLICATION_ID environment variable \n\nAdd a new environment variable with the name `MOESIF_APPLICATION_ID` and the value being your Moesif application id,\nwhich can be found in the [_Moesif Portal_](https://www.moesif.com/).\nAfter signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps. \n\nYou can always find your Moesif Application Id at any time by logging \ninto the [_Moesif Portal_](https://www.moesif.com/), click on the top right menu,\n and then clicking _Installation_.\n\n### 3. Trigger your API\nGrab the URL to your API Gateway or LB and make some calls using a tool like Postman or CURL. \n\n> In order for your event 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## Repo file structure\n\n- `moesif_aws_lambda/middleware.py` the middleware library\n- `lambda_function.py` sample AWS Lambda function using the middleware\n\n## Optional: Capturing outgoing API calls\nIf you want to capture all outgoing API calls from your Python Lambda function to third parties like\nStripe or to your own dependencies, call `start_capture_outgoing()` to start capturing. This mechanism works by \npatching the [Requests](https://requests.readthedocs.io/en/master/) \n\n```python\nfrom moesif_aws_lambda.middleware import *\nstart_capture_outgoing(moesif_options) # moesif_options are the configuration options.\n```\n\n## Configuration options\n\n### __`IDENTIFY_USER`__\n\nType: `(event, context) => String`\n\n`IDENTIFY_USER` is a function that takes AWS lambda `event` and `context` objects as arguments\nand returns a user_id. This enables Moesif to attribute API requests to individual unique users\nso you can understand who calling your API. This can be used simultaneously with `IDENTIFY_COMPANY`\nto track both individual customers and the companies their a part of.\n\n\n```python\ndef identify_user(event, context):\n  # your code here, must return a string\n  return event[\"requestContext\"][\"identity\"][\"cognitoIdentityId\"]\n```\n\n### __`IDENTIFY_COMPANY`__\n\nType: `(event, context) => String`\n\n`IDENTIFY_COMPANY` is a function that takes AWS lambda `event` and `context` objects as arguments\nand returns a company_id. If your business is B2B, this enables Moesif to attribute \nAPI requests to specific companies or organizations so you can understand which accounts are \ncalling your API. This can be used simultaneously with `IDENTIFY_USER` to track both \nindividual customers and the companies their a part of. \n\n\n```python\ndef identify_company(event, context):\n  # your code here, must return a string\n  return '7890'\n}\n```\n\n### __`GET_SESSION_TOKEN`__\n\nType: `(event, context) => String`\n\n`GET_SESSION_TOKEN` a function that takes AWS lambda `event` and `context` objects as arguments and returns a\nsession token (i.e. such as an API key).\n\n\n```python\ndef get_session_token(event, context):\n    # your code here, must return a string.\n    return 'XXXXXXXXX'\n```\n\n### __`GET_API_VERSION`__\n\nType: `(event, context) => String`\n\n`GET_API_VERSION` is a 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\n```python\ndef get_api_version(event, context):\n  # your code here. must return a string.\n  return '1.0.0'\n```\n\n### __`GET_METADATA`__\n\nType: `(event, context) => String`\n\n`GET_METADATA` is a function that AWS lambda `event` and `context` objects as arguments and returns an object that allows you to add custom metadata that will be associated with the request. The metadata must be a simple python object that can be converted to JSON. For example, you may want to save a function_name, a trace_id, or request_context with the request.\n\n\n```python\ndef get_metadata(event, context):\n  # your code here:\n  return {\n        'trace_id': context.aws_request_id,\n        'function_name': context.function_name,\n        'request_context': event['requestContext']\n    }\n```\n\n### __`SKIP`__\n\nType: `(event, context) => Boolean`\n\n`SKIP` is a function that takes AWS lambda `event` and `context` objects as arguments and returns true\nif the event should be skipped (i.e. not logged)\n<br/>_The default is shown below and skips requests to the root path \"/\"._\n\n\n```python\ndef should_skip(event, context):\n    # your code here. must return a boolean.\n    return \"/\" in event['path']\n```\n\n### __`MASK_EVENT_MODEL`__\n\nType: `MoesifEventModel => MoesifEventModel`\n\n`MASK_EVENT_MODEL` is a function that takes the final Moesif event model (rather than the AWS lambda event/context objects) as an argument before being sent to Moesif. With maskContent, you can make modifications to headers or body such as removing certain header or body fields.\n\n```python\ndef mask_event(eventmodel):\n  # remove any field that you don't want to be sent to Moesif.\n  return eventmodel\n ```\n\n### __`DEBUG`__\n\nType: `Boolean`\n\nSet to true to print debug logs if you're having integration issues. \n\n### __`LOG_BODY`__\n\nType: `Boolean`\n\n`LOG_BODY` is default to true, set to false to remove logging request and response body to Moesif.\n\n## Options for logging outgoing calls\n\nThe options below are applied to outgoing API calls. The request and response objects passed in are  [Requests](https://requests.readthedocs.io/en/master/user/advanced/#request-and-response-objects) request and [Response](https://requests.readthedocs.io/en/master/user/advanced/#request-and-response-objects) response objects.\n\n### __`SKIP_OUTGOING`__\n(optional) _(req, res) => boolean_, a function that takes a [Requests](https://requests.readthedocs.io/en/master/) request and response,\nand returns true if you want to skip this particular event.\n\n### __`IDENTIFY_USER_OUTGOING`__\n(optional, but highly recommended) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the user id used by your system. While Moesif tries to identify users automatically,\nbut different frameworks and your implementation might be very different, it would be helpful and much more accurate to provide this function.\n\n### __`IDENTIFY_COMPANY_OUTGOING`__\n(optional) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the company id for this event.\n\n### __`GET_METADATA_OUTGOING`__\n(optional) _(req, res) => dictionary_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and\nreturns a dictionary (must be able to be encoded into JSON). This allows\nto associate this event with custom metadata. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.\n\n### __`GET_SESSION_TOKEN_OUTGOING`__\n(optional) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.\n\n### __`LOG_BODY_OUTGOING`__\n(optional) _boolean_, default True, Set to False to remove logging request and response body.\n\n## Update User\n\n### Update A Single User\nCreate or update a user profile in Moesif.\nThe metadata field can be any customer demographic or other info you want to store.\nOnly the `user_id` field is required.\nFor details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-a-user).\n\n```python\nfrom moesif_aws_lambda.middleware import *\n\nmoesif_options = {\n    'LOG_BODY': True,\n    'DEBUG': True,\n}\n\n# Only user_id 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\nuser = {\n  'user_id': '12345',\n  'company_id': '67890', # If set, associate user with a company object\n  'campaign': {\n    'utm_source': 'google',\n    'utm_medium': 'cpc',\n    'utm_campaign': 'adwords',\n    'utm_term': 'api+tooling',\n    'utm_content': 'landing'\n  },\n  'metadata': {\n    'email': 'john@acmeinc.com',\n    'first_name': 'John',\n    'last_name': 'Doe',\n    'title': 'Software Engineer',\n    'sales_info': {\n        'stage': 'Customer',\n        'lifetime_value': 24000,\n        'account_owner': 'mary@contoso.com'\n    },\n  }\n}\n\nupdate_user(user, moesif_options)\n```\n\n### Update Users in Batch\nSimilar to update_user, but used to update a list of users in one batch.\nOnly the `user_id` field is required.\nFor details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-users-in-batch).\n\n```python\nfrom moesif_aws_lambda.middleware import *\n\nmoesif_options = {\n    'LOG_BODY': True,\n    'DEBUG': True,\n}\n\nuserA = {\n  'user_id': '12345',\n  'company_id': '67890', # If set, associate user with a company object\n  'metadata': {\n    'email': 'john@acmeinc.com',\n    'first_name': 'John',\n    'last_name': 'Doe',\n    'title': 'Software Engineer',\n    'sales_info': {\n        'stage': 'Customer',\n        'lifetime_value': 24000,\n        'account_owner': 'mary@contoso.com'\n    },\n  }\n}\n\nuserB = {\n  'user_id': '54321',\n  'company_id': '67890', # If set, associate user with a company object\n  'metadata': {\n    'email': 'mary@acmeinc.com',\n    'first_name': 'Mary',\n    'last_name': 'Jane',\n    'title': 'Software Engineer',\n    'sales_info': {\n        'stage': 'Customer',\n        'lifetime_value': 48000,\n        'account_owner': 'mary@contoso.com'\n    },\n  }\n}\nupdate_users_batch([userA, userB], moesif_options)\n```\n\n## Update Company\n\n### Update A Single Company\nCreate or update a company profile in Moesif.\nThe metadata field can be any company demographic or other info you want to store.\nOnly the `company_id` field is required.\nFor details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-a-company).\n\n```python\nfrom moesif_aws_lambda.middleware import *\n\nmoesif_options = {\n    'LOG_BODY': True,\n    'DEBUG': True,\n}\n\n# Only company_id 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\ncompany = {\n  'company_id': '67890',\n  'company_domain': 'acmeinc.com', # If domain is set, Moesif will enrich your profiles with publicly available info\n  'campaign': {\n    'utm_source': 'google',\n    'utm_medium': 'cpc',\n    'utm_campaign': 'adwords',\n    'utm_term': 'api+tooling',\n    'utm_content': 'landing'\n  },\n  'metadata': {\n    'org_name': 'Acme, Inc',\n    'plan_name': 'Free',\n    'deal_stage': 'Lead',\n    'mrr': 24000,\n    'demographics': {\n        'alexa_ranking': 500000,\n        'employee_count': 47\n    },\n  }\n}\n\nupdate_company(company, moesif_options)\n```\n\n### Update Companies in Batch\nSimilar to update_company, but used to update a list of companies in one batch.\nOnly the `company_id` field is required.\nFor details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-companies-in-batch).\n\n```python\nfrom moesif_aws_lambda.middleware import *\n\nmoesif_options = {\n    'LOG_BODY': True,\n    'DEBUG': True,\n}\n\ncompanyA = {\n  'company_id': '67890',\n  'company_domain': 'acmeinc.com', # If domain is set, Moesif will enrich your profiles with publicly available info\n  'metadata': {\n    'org_name': 'Acme, Inc',\n    'plan_name': 'Free',\n    'deal_stage': 'Lead',\n    'mrr': 24000,\n    'demographics': {\n        'alexa_ranking': 500000,\n        'employee_count': 47\n    },\n  }\n}\n\ncompanyB = {\n  'company_id': '09876',\n  'company_domain': 'contoso.com', # If domain is set, Moesif will enrich your profiles with publicly available info\n  'metadata': {\n    'org_name': 'Contoso, Inc',\n    'plan_name': 'Free',\n    'deal_stage': 'Lead',\n    'mrr': 48000,\n    'demographics': {\n        'alexa_ranking': 500000,\n        'employee_count': 53\n    },\n  }\n}\n\nupdate_companies_batch([companyA, companyB], moesif_options)\n```\n\n## Examples\n\n- [A complete example is available on GitHub](https://github.com/Moesif/moesif-aws-lambda-python-example).\n\n## Other integrations\n\nTo view more documentation on integration options, please visit __[the Integration Options Documentation](https://www.moesif.com/docs/getting-started/integration-options/).__\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-python.svg?style=social\n\n[link-built-for]: https://aws.amazon.com/lambda/\n[link-license]: https://raw.githubusercontent.com/Moesif/moesif-aws-lambda-python/master/LICENSE\n[link-source]: https://github.com/moesif/moesif-aws-lambda-python\n",
    "bugtrack_url": null,
    "license": "Apache Software License",
    "summary": "Moesif Middleware to automatically log API calls from AWS Lambda functions",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://www.moesif.com/docs/server-integration/aws-lambda-python/"
    },
    "split_keywords": [
        "moesif",
        "aws",
        "serverless",
        "api",
        "gateway",
        "lambda",
        "debug",
        "logging",
        "trace",
        "analytics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "efdfb7e0c8354ed0d34f488f8192da6ac97a0b3b1e5ff1edbcfc04807effab85",
                "md5": "6744894b69fe5a93255d81eb28a9d2ae",
                "sha256": "eae50e6c205e9877f6eb2ded2f940eee8fc5fb2eaa322d4b5ef9e81f15f19ad5"
            },
            "downloads": -1,
            "filename": "moesif_aws_lambda-1.2.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6744894b69fe5a93255d81eb28a9d2ae",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 18842,
            "upload_time": "2023-11-02T06:50:56",
            "upload_time_iso_8601": "2023-11-02T06:50:56.399046Z",
            "url": "https://files.pythonhosted.org/packages/ef/df/b7e0c8354ed0d34f488f8192da6ac97a0b3b1e5ff1edbcfc04807effab85/moesif_aws_lambda-1.2.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e13b089a0a618f6dd258262266966ed5f3f6b51c2b9ec8888e7989659055cee",
                "md5": "a09bde590c2ed4c24d67f7d549c74a55",
                "sha256": "623a4d26ef498cc0bc988b7c4b90c360c0328d2dc665a04cb3a8bdcbe2765c57"
            },
            "downloads": -1,
            "filename": "moesif_aws_lambda-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a09bde590c2ed4c24d67f7d549c74a55",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21709,
            "upload_time": "2023-11-02T06:51:06",
            "upload_time_iso_8601": "2023-11-02T06:51:06.633342Z",
            "url": "https://files.pythonhosted.org/packages/3e/13/b089a0a618f6dd258262266966ed5f3f6b51c2b9ec8888e7989659055cee/moesif_aws_lambda-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-02 06:51:06",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "moesif-aws-lambda"
}
        
Elapsed time: 2.16243s