Skip to content

Feature request: Parsing nested Parser envelopes #2691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
heitorlessa opened this issue Jul 6, 2023 Discussed in #2287 · 4 comments
Closed

Feature request: Parsing nested Parser envelopes #2691

heitorlessa opened this issue Jul 6, 2023 Discussed in #2287 · 4 comments
Labels
feature-request feature request parser Parser (Pydantic) utility rejected

Comments

@heitorlessa
Copy link
Contributor

Discussed in #2287

Related: #2678

Originally posted by sk0g May 18, 2023
So we have payloads that are essentially Kinesis Firehouse events containing an SQS event. Is there a way to unwrap this using @event_parser()? If not, what's the next best thing?

@heitorlessa
Copy link
Contributor Author

Note: we have a RFC for Event Source Data Classes but not for Parser (after the former is done).

#2678

@heitorlessa heitorlessa moved this from Triage to Backlog in Powertools for AWS Lambda (Python) Jul 10, 2023
@heitorlessa heitorlessa added the help wanted Could use a second pair of eyes/hands label Jul 10, 2023
@aradyaron
Copy link
Contributor

aradyaron commented Sep 16, 2023

Hey @heitorlessa.
I've tried to check this a bit, and even experimented with the implementation.
You can check the implementation itself here
aradyaron#3

Please note that It's a bit problematic for me to get a nested event, so if you got some examples of such payloads and scenarios, it will allow to further implement this feature.

Please see that this Pr Contains two new functions

def chained_parse(event: Dict[str, Any], model: Type[Model], envelopes: List[Type[Envelope]]) -> List:

which receives a list of envelopes to extract the nested event from.
It returns a list of the given model type.
It also assumes one each nesting can be a list of event, so it expands the events into a flat list.

In case the model itself is not to be parsed as an envelope, the last envelope can be None

For example:

   parsed_event: List[MySnsBusiness] = chained_parse(
       event=raw_event,
       model=MySnsBusiness,
       envelopes=[envelopes.X, envelopes.Y, None],
   )

same with

@lambda_handler_decorator
def event_parser(
   handler: Callable[[Any, LambdaContext], EventParserReturnType],
   event: Dict[str, Any],
   context: LambdaContext,
   model: Type[Model],
   envelope: Optional[Union[Type[Envelope], List[Type[Envelope]]]] = None,
) -> EventParserReturnType:

which in case envelope is a list, will use chained envelope with the same logic.

WDYT about this kind of solution? Please note that without actual nested use cases it's purely a theoretical solution

@anafalcao
Copy link
Contributor

We are closing this issue since it hasn't gotten much traction since it was open.
At this time we're not planning on creating a generic nested parser but we are open to consider implementing ad-hoc models for specific integrations.
If you see the need for one of these, please open a dedicated issue describing your use case.

@anafalcao anafalcao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Coming soon in Powertools for AWS Lambda (Python) Jan 23, 2025
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@dreamorosi dreamorosi added rejected and removed help wanted Could use a second pair of eyes/hands labels Jan 23, 2025
@dreamorosi dreamorosi moved this from Coming soon to Closed in Powertools for AWS Lambda (Python) Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request parser Parser (Pydantic) utility rejected
Projects
Development

No branches or pull requests

4 participants