aws-powertools/powertools-lambda-python

Tech debt: Improve documentation of Event model fields in CloudWatch parser models

Closed this issue · 6 comments

Description

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

Motivation

Currently, the CloudWatch 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/cloudwatch.py

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

  • cloudWatchLogsEvent.json
  • cloudWatchAlarmEvent.json
  • cloudWatchCustomWidgetEvent.json

Implementation Requirements

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

Example Implementation

# Before
class CloudWatchLogsDecode(BaseModel):
    messageType: str
    owner: str
    logGroup: str
    logStream: str
    subscriptionFilters: List[str]
    logEvents: List[CloudWatchLogsLogEvent]
    policyLevel: Optional[str] = None

# After  
class CloudWatchLogsDecode(BaseModel):
    messageType: str = Field(
        description="The type of CloudWatch Logs message.",
        examples=[
            "DATA_MESSAGE",
            "CONTROL_MESSAGE"
        ]
    )
    owner: str = Field(
        description="The AWS account ID of the originating log data.",
        examples=[
            "123456789012",
            "987654321098"
        ]
    )
    logGroup: str = Field(
        description="The name of the log group.",
        examples=[
            "/aws/lambda/my-function",
            "/aws/apigateway/my-api",
            "my-application-logs"
        ]
    )
    log_stream: str = Field(
        description="The name of the log stream.",
        examples=[
            "2023/01/15/[$LATEST]abcdef1234567890",
            "i-1234567890abcdef0",
            "my-stream-2023-01-15"
        ]
    )

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

Hey, could you assign this to me

Hey, could you assign this to me

Sure thing @sreejaaryahi18! Go ahead pls.

Hi @sreejaaryahi18, just checking in to see how you were progressing with the PR for this issue.

Are you still working on it? Is there anything else that we can do to help?

Hi @dreamorosi , I haven’t had a chance to start on this yet as I’m a bit occupied ,I still plan to work on it, let me know if that’s okay

Yes, thats ok @sreejaaryahi18! Pls 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.