I was looking out for a structure like DTO to store data from json in a AWS python Lambda. I came across dataclasses in python and tried it to create simple dto for the json data. My project contains lot of lambdas and heavy json parsing. I had been using dict till now to handle parsed json. please guide me if dataclasses as a standalone module from python is a right way to go for DTO kind of functionality in aws python lambda? And I have included these dtos in lambda layer for reusability across other lambdas I am worried that for nested data mainitainaing these dataclasses will be difficult.
Adding a code snippet for ref: lambda_handler.py
from dataclasses import asdict
from custom_functions.epicervix_dto import EpicervixDto
from custom_functions.dto_class import Dejlog
def lambda_handler(event, context):
a = Dejlog(**event)
return {
'statusCode': 200,
'body': json.dumps(asdict(b))
}
dto_class.py from lambda layer
from dataclasses import dataclass, field
from typing import Any
@dataclass
class Dejlog:
PK: str
SK: str
eventtype: str
result: Any
type: str = field(init=False, repr=False, default=None)
status: str
event:str = field(init=False, repr=False, default=None)