Metadata-Version: 2.1
Name: xlambda-helper
Version: 0.0.3
Summary: Helper library to handle warming requests from X-Lambda (more: https://bit.ly/xlambda).
Home-page: https://github.com/dashbird/xlambda-helper-python/archive/0.0.3.tar.gz
Author: Dashbird.io (Renato Byrro)
Author-email: renato@dashbird.io
License: MIT
Keywords: x-lambda,xlambda,aws,aws lambda,cold start,warm,serverless,containers
Platform: UNKNOWN
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Description-Content-Type: text/markdown
Requires-Dist: boto3

# X-Lambda Helper (Python version)

A Python library to help handle warm-up requests generated by [X-Lambda](https://github.com/dashbird/xlambda).

[X-Lambda](https://github.com/dashbird/xlambda) predicts [AWS Lambda](https://aws.amazon.com/lambda/) demand and keeps a fleet of containers warm to mitigate cold-start latency. Warm invocations sent by X-Lambda are received by a Lambda function, which needs to respond accordingly.

This **X-Lambda Helper** project helps to handle warm invocations in Python functions.

## Requirements

- [Python 3.6+](https://www.python.org/downloads/)
- [AWS account](https://aws.amazon.com/account/)

## Quick start

1. Install X-Lambda Helper: `pip install xlambda_helper`.
2. Decorate your [Lambda handler](https://docs.aws.amazon.com/lambda/latest/dg/python-programming-model-handler-types.html) following the example below:
3. Deploy your code in AWS Lambda.

### Usage example

```python
import xlambda_helper


@xlambda_helper.warm()
def handler(event, context):
    # Your original code goes here
    x_men = [
        {'Charles': 'Professor Xavier'},
        {'Logan': 'Wolverine'},
        {'Jean': 'Phoenix'},
        {'Scott': 'Cyclops'}
    ]

    return x_men
```

## About

X-Lambda Helper will be executed every time your handler is invoked by AWS Lambda. It will check whether the invocation is a warming request coming from X-Lambda. If not, it will run your handler code normally. If yes, it will short-circuit to return a default answer and will not execute the handler function.

When handling warm requests, X-Lambda Helper will automatically adjust your function behavior:

- Check whether it was a cold start
- Sleep for a period of time, if needed
- Defer to your original handler function, if invocation is not a warm request


