-
Notifications
You must be signed in to change notification settings - Fork 5
/
wolverine.py
67 lines (51 loc) · 1.55 KB
/
wolverine.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import logging
import traceback
from typing import Dict
try:
import unzip_requirements # NOQA
except ImportError:
pass
from xlibs import exc, response
from xlibs.wolverine import utils
from xlibs.wolverine.constants import REQUIRED_ARGS
logger = logging.getLogger()
logger.setLevel(logging.WARNING)
def handler(event: Dict, context: Dict) -> Dict:
'''Wolverine Lambda entry point handler
:arg event: (dict) event input received from the invoker/trigger
:arg context: (dict) contextual data provided by the Lambda platform
'''
try:
result = execute(
options=event,
)
return response.build(
status=200,
data=result,
)
except Exception as error:
logger.exception(error)
return response.build(
status=500,
error={
'type': type(error).__name__,
'description': str(error),
'trace': traceback.format_exc(),
},
original_request=event,
)
def execute(*, options):
'''Execute a request received by the Wolverine Lambda'''
is_request_valid, validation_msg = utils.validate_request(
options=options,
required_args=REQUIRED_ARGS,
)
if not is_request_valid:
raise exc.XLambdaExceptionInvalidRequest(validation_msg)
metrics, settings = utils.get_lambda_info(
function_name=options['name'],
region=options['region'],
)
options['metrics'] = metrics
options['settings'] = settings
return options