forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapigw.py
32 lines (25 loc) · 1.06 KB
/
apigw.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
import logging
from typing import Any, Dict, Optional, Type, Union
from ..models import APIGatewayProxyEventModel
from ..types import Model
from .base import BaseEnvelope
logger = logging.getLogger(__name__)
class ApiGatewayEnvelope(BaseEnvelope):
"""API Gateway envelope to extract data within body key"""
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> Optional[Model]:
"""Parses data found with model provided
Parameters
----------
data : Dict
Lambda event to be parsed
model : Type[Model]
Data model provided to parse after extracting data using envelope
Returns
-------
Any
Parsed detail payload with model provided
"""
logger.debug(f"Parsing incoming data with Api Gateway model {APIGatewayProxyEventModel}")
parsed_envelope = APIGatewayProxyEventModel.parse_obj(data)
logger.debug(f"Parsing event payload in `detail` with {model}")
return self._parse(data=parsed_envelope.body, model=model)