-
Notifications
You must be signed in to change notification settings - Fork 421
Feature: Advanced parser utility #147
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
Comments
I like the idea of using JSON schemas strictly for validating AWS managed event types that don’t change. Validating the payload would be the responsibility of the consumer (using pydantic or something similar). |
My preference would be to use pydantic having the ability to add business rule validation would be beneficial to me. I actually ran into the issue of having to set my date field to a string in the JSON schema because the date is optional... With pydantic, you can have an |
I always use pydantic for Lambda for events and payload. However, The library is a little heavy for lambda. I suggest Pydantic is supplied as an option. Also, I develop a code-generator that generates pydantic models from JSON Schema. Additionally, this code generator can create models from JSON data. BackgroundsI created an experimental project that provides pydantic models for events. I often define pydantic models for events in my project. |
hey @koxudaxi - This is interesting! I was under the impression only the wheels was going to count (8.2M for manylinux). It's also great to hear you created all these Pydantic tooling as I still have questions about the UX and code generation :) -- TIL. At the moment, we're collecting customer demand on Pydantic usage within Serverless. We want to support it (see #118), but we're also mindful of justifying customer demand, Pydantic as an extra dependency, simplified UX, how much we want to abstract, and docs to ease the transition from JSON Schemas to Pydantic. We're on the fence as to whether create a single Would love to hear feedback on this front -- And yes, we'd be happy to maintain models for Lambda Event Sources (only), hence a longer discussion so we can get Pydantic right without breaking our Tenets |
This proposal is great ! It's something really useful I've been wishing for a long time. About the description, it's unclear to me why do we need to create JSON schemas representing AWS event types instead of python annotations - don't read as critic please, I really don't know. For my use case, the killer feature of using pydantic or any other "parsing" lib is that we can deal with objects, validate/add business behavior we're unable to do in a schema. What are the use cases for JSONSchema and pydantic ? @heitorlessa , maybe I'm going "too far" but IMO two points need to be discussed, at least in a "design" level. First one is related with the input parsing, it would be great to design something plugable, e.g, codebase of client X is entirely written in marshmallow, are we going to force him to rewrite everything to a new standard ? Maybe few cases, but I'm sure we can provide an interface to plug any parsing lib he's used to - powertools shouldn't provide them. About the second one, our utility must explicitly require the what/how to correctly parse a message. "What" is an AWS event source and the "How", a schema - looks like you've already done this in your pr. About pydantic, I'd be great to see it here, as an extra dependency, for sure. Add it to a layer and we're "done". |
@gmcrocetti @koxudaxi you can see my pydantic PR #118. |
It's compressed. You may be surprised when extracting it. OK, I have understood what we should discuss in this phase. I write about the great UX of Pydantic. Lambda Event objects are deeply and nested structures. Pydantic clear these problems. I want to hear other "customers" too. |
@risenberg-cyberark |
Everyone - This is now available in the 1.7.0 release. |
Is your feature request related to a problem? Please describe.
We've heard from a small number of customers that parsing Lambda Event Source payloads require a considerable effort since these don't have official schemas for Python.
With parsing and classes modelled after these schemas, they can have the benefits of runtime type safety, custom validations on possible values pertinent to their use case, autocomplete, and only parse fields they're interested in.
Describe the solution you'd like
Solution is two-fold:
parser
utility that uses Pydantic to parse and validate incoming/outgoing events, and allow customers to use their own data modelsThis would reduce the amount of time developers invest searching for official data structure for each event source, improve their security posture on incoming and outgoing events, and increased developer productivity.
Describe alternatives you've considered
Challenge with JSON Schemas is they typically don't validate business rules for incoming/outgoing events, but merely a schema.
Additional context
Initial implementation that lacked customer data points as of now, but could be revisited depending on interest for thisfeature: #118
The text was updated successfully, but these errors were encountered: