-
Notifications
You must be signed in to change notification settings - Fork 444
refactor(parser): Improve DynamoDB models with examples and descriptions #7146
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
base: develop
Are you sure you want to change the base?
refactor(parser): Improve DynamoDB models with examples and descriptions #7146
Conversation
…ields in DynamoDB parser models
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sreejaaryahi18 this is a super nice work, thanks a lot for working on this! I just left some few comments that we need to address before merging it.
Please let me know if you need any additional help
# if stream_type == "NEW_AND_OLD_IMAGES" and not new_img and not old_img: # noqa: ERA001 | ||
# raise TypeError("DynamoDB streams model failed validation, missing both new & old stream images") # noqa: ERA001,E501 | ||
# return values # noqa: ERA001 | ||
ApproximateCreationDateTime: Optional[float] = Field( # AWS sends this as Unix epoch float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ApproximateCreationDateTime: Optional[float] = Field( # AWS sends this as Unix epoch float | |
ApproximateCreationDateTime: Optional[datetime] = Field( # AWS sends this as Unix epoch float |
We set this field to a timestamp so that Pydantic can convert it automatically. Also, changing this will break customers using this field as timestamp.
|
||
@field_validator("Keys", "NewImage", "OldImage", mode="before") | ||
def deserialize_field(cls, value): | ||
return {k: _DESERIALIZER.deserialize(v) for k, v in value.items()} | ||
return {k: _DESERIALIZER.deserialize(v) for k, v in value.items()} if value else value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can yu please remove this if condition?
description="The type of identity that made the request, which is always 'Service' for DynamoDB streams.", | ||
examples=["Service"] | ||
) | ||
principalId: str = Field( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
principalId: str = Field( | |
principalId: Literal["dynamodb.amazonaws.com"] = Field( |
description="The type of operation that was performed on the item.", | ||
examples=["INSERT"] | ||
) | ||
eventVersion: str = Field( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventVersion: str = Field( | |
eventVersion: float = Field( |
description="The version of the stream record format.", | ||
examples=["1.0"] | ||
) | ||
eventSource: str = Field( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventSource: str = Field( | |
eventSource: Literal["aws:dynamodb"] = Field( |
Hey @sreejaaryahi18 can you please run |
|
Hey @leandrodamascena Ive made the changes, could you check its right now? |
Issue number: #7123
Summary
Added description and examples parameters to all fields in DynamoDB parser models (aws_lambda_powertools/utilities/parser/models/dynamodb.py) using Field().
These additions provide detailed explanations and realistic example values based on AWS DynamoDB official documentation and sample event.
Changes
User experience
Before this update, the DynamoDB parser models lacked descriptive metadata and examples, making it harder for users to understand field purposes and expected values.
After this update, developers will have clearer, documented field descriptions and example values that improve usability, reduce confusion, and enhance validation confidence when working with DynamoDB stream events
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
NoRFC issue number:
#7123
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.