Skip to content

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sreejaaryahi18
Copy link

@sreejaaryahi18 sreejaaryahi18 commented Aug 10, 2025

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

Please provide a summary of what's being changed

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

Please share what the user experience looks like before and after this change

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change? No

RFC issue number:
#7123

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

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.

@sreejaaryahi18 sreejaaryahi18 requested a review from a team as a code owner August 10, 2025 14:42
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 10, 2025
Copy link

boring-cyborg bot commented Aug 10, 2025

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@sreejaaryahi18 sreejaaryahi18 changed the title #7123 Tech debt: Improve documentation of Event model fields in Dynam… docs(#7123): add descriptions and examples to DynamoDB parser model fields Aug 10, 2025
@leandrodamascena leandrodamascena changed the title docs(#7123): add descriptions and examples to DynamoDB parser model fields refactor(parser): Improve DynamoDB models with examples and descriptions Aug 11, 2025
Copy link
Contributor

@leandrodamascena leandrodamascena left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eventVersion: str = Field(
eventVersion: float = Field(

description="The version of the stream record format.",
examples=["1.0"]
)
eventSource: str = Field(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eventSource: str = Field(
eventSource: Literal["aws:dynamodb"] = Field(

@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement labels Aug 11, 2025
@leandrodamascena
Copy link
Contributor

Hey @sreejaaryahi18 can you please run make format and push the code again?

Copy link

@sreejaaryahi18
Copy link
Author

Hey @leandrodamascena Ive made the changes, could you check its right now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tech debt: Improve documentation of Event model fields in DynamoDB parser models
2 participants