aws-powertools/powertools-lambda-python

Tech debt: Improve documentation of Event model fields in S3 parser Models

Closed this issue · 3 comments

Description

Enhance the S3 parser models with field descriptions and examples using Pydantic's Field() functionality. This improvement will provide better documentation and metadata for S3 event parsing, following the pattern established in PR #7100.

Motivation

Currently, the S3 models lack detailed field documentation, making it harder for developers to:

  • Understand field purposes without referencing external AWS documentation
  • Generate rich API documentation with tools like Swagger/OpenAPI
  • Create realistic test data using model factories
  • Get helpful IntelliSense in IDEs

Proposed Changes

Add description and examples parameters to all fields in the following models using Field():

Files to modify:

  • aws_lambda_powertools/utilities/parser/models/s3.py

Reference events:
Check the sample events in tests/events/ for realistic field values:

  • s3Event.json
  • s3EventBatch.json
  • s3EventBridgeNotification.json

Implementation Requirements

  • ✅ Add detailed description for each field explaining its purpose and usage
  • ✅ Include practical examples showing realistic AWS S3 values
  • ✅ Base descriptions on official AWS S3 documentation
  • ✅ Maintain all existing functionality, types, and validation logic
  • ✅ Follow the same pattern established in EventBridge, Kinesis, and ALB models

Example Implementation

# Before
class S3EventNotificationObjectModel(BaseModel):
    key: str
    size: Optional[NonNegativeFloat] = None
    etag: str = Field(default="")
    version_id: Optional[str] = Field(None, alias="version-id")
    sequencer: Optional[str] = None

# After  
class S3EventNotificationObjectModel(BaseModel):
    key: str = Field(
        description="The object key (file name) of the S3 object.",
        examples=[
            "my-image.jpg",
            "documents/report.pdf",
            "logs/2023/01/15/app.log"
        ]
    )
    size: Optional[NonNegativeFloat] = Field(
        None,
        description="The size of the object in bytes.",
        examples=[1024, 2048576, 0]
    )
    etag: str = Field(
        default="",
        description="The entity tag (ETag) of the object.",
        examples=[
            "d41d8cd98f00b204e9800998ecf8427e",
            "098f6bcd4621d373cade4e832627b4f6"
        ]
    )
    version_id: Optional[str] = Field(
        None, 
        alias="version-id",
        description="The version ID of the object (if versioning is enabled).",
        examples=[
            "096fKKXTRTtl3on89fVO.nfljtsv6qko",
            "null"
        ]
    )
    sequencer: Optional[str] = Field(
        None,
        description="A string representation of a hexadecimal value used to determine event sequence.",
        examples=[
            "0A1B2C3D4E5F678901",
            "005B21C13A6F24045E"
        ]
    )

Benefits

For Developers

  • Better IntelliSense with field descriptions and example values
  • Self-documenting code without needing external AWS documentation
  • Faster development with immediate reference for acceptable values

For Documentation Tools

  • Rich Swagger/OpenAPI docs via .model_json_schema()
  • Automated documentation generation with comprehensive metadata
  • Interactive documentation with practical examples

Getting Started

This is a great first issue for newcomers to Powertools for AWS! The task is straightforward and helps you get familiar with our codebase structure.

Need help?

We're here to support you! Feel free to:

  • Ask questions in the comments
  • Request guidance on implementation approach

Acknowledgment

Hello :)

I would like to work on this issue.

Hello :)

I would like to work on this issue.

Ohhh you're here my friend!! PLEASE GO AHEAD! ❤️

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 reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.