generated from MITLibraries/python-lambda-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambdas.py
35 lines (25 loc) · 1.07 KB
/
lambdas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
import logging
from apig_wsgi import make_lambda_handler
from webapp import create_app
from webapp.config import Config, configure_logger, configure_sentry
logger = logging.getLogger(__name__)
CONFIG = Config()
def lambda_handler(event: dict, context: dict) -> dict:
"""Launches the Flask app when the Lambda function is invoked.
This is achieved by using the library 'apig-wsgi' to wrap the Flask app in an
AWS Lambda handler function. This wrapper converts the Function URL
request payload into a WSGI object for the Flask app, then converts the
Flask app response into a payload suitable for the Lambda Function URL
to return to the caller.
See https://github.com/adamchainz/apig-wsgi/tree/main.
"""
CONFIG.check_required_env_vars()
logger.info(configure_logger(verbose=True))
logger.info(configure_sentry())
apig_wsgi_handler = make_lambda_handler(create_app())
try:
logger.debug(json.dumps(event))
except TypeError as error:
logger.warning(error)
return apig_wsgi_handler(event, context)