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
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:
Proposed Changes
Add
descriptionandexamplesparameters to all fields in the following models usingField():Files to modify:
aws_lambda_powertools/utilities/parser/models/cloudwatch.pyReference events:
Check the sample events in
tests/events/for realistic field values:cloudWatchLogsEvent.jsoncloudWatchAlarmEvent.jsoncloudWatchCustomWidgetEvent.jsonImplementation Requirements
descriptionfor each field explaining its purpose and usageexamplesshowing realistic AWS CloudWatch valuesExample Implementation
Benefits
For Developers
For Documentation Tools
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:
Acknowledgment