File size: 642 Bytes
e868a55
 
 
 
 
 
 
 
9772e97
e868a55
 
 
 
 
 
 
 
9772e97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Ref. [Deploying a Machine Learning Model to AWS Lambda | TestDriven.io](https://testdriven.io/blog/ml-model-aws-lambda/)
import logging
from app import DocumentParserModel

# initialize logger and model during Lambda's cold start
LOGGER = logging.getLogger()
LOGGER.setLevel(logging.INFO)

model = DocumentParserModel()


def lambda_handle(event, context):
    # Only used to keep the Lambda warm
    if event.get("source") == "KEEP_LAMBDA_WARM":
        LOGGER.info("No ML work to do. Just staying warm...")
        return "Keeping Lambda warm"

    return {"statusCode": 200, "result": model.predict_text(image_blob=event["image_blob"])}