Description
Enhance the SNS parser models with field descriptions and examples using Pydantic's Field() functionality. This improvement will provide better documentation and metadata for SNS event parsing, following the pattern established in PR #7100.
Motivation
Currently, the SNS 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/sns.py
Reference events:
Check the sample events in tests/events/ for realistic field values:
snsEvent.json
snsEventBatch.json
Implementation Requirements
- ✅ Add detailed
description for each field explaining its purpose and usage
- ✅ Include practical
examples showing realistic AWS SNS values
- ✅ Base descriptions on official AWS SNS documentation
- ✅ Maintain all existing functionality, types, and validation logic
- ✅ Follow the same pattern established in EventBridge, Kinesis, and ALB models
Example Implementation
# Before
class SnsNotificationModel(BaseModel):
message_id: str
topic_arn: str
subject: str
message: str
timestamp: datetime
# After
class SnsNotificationModel(BaseModel):
message_id: str = Field(
description="A Universally Unique Identifier, unique for each message published.",
examples=[
"95df01b4-ee98-5cb9-9903-4c221d41eb5e",
"da41e39f-ea4d-435a-b922-c6aae3915ebe"
]
)
topic_arn: str = Field(
description="The Amazon Resource Name (ARN) for the topic that this message was published to.",
examples=[
"arn:aws:sns:us-east-1:123456789012:my-topic",
"arn:aws:sns:eu-west-1:123456789012:notification-topic"
]
)
subject: str = Field(
description="The subject parameter provided when the notification was published to the topic.",
examples=[
"Test notification",
"Alert: System maintenance scheduled"
]
)
message: str = Field(
description="The message value specified when the notification was published to the topic.",
examples=[
"Hello from SNS!",
'{"alert": "CPU usage above 80%", "instance": "i-1234567890abcdef0"}'
]
)
timestamp: datetime = Field(
description="The time (GMT) when the notification was published.",
examples=[
"2023-01-15T10:30:00.000Z",
"2023-12-25T18:45:30.123Z"
]
)
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 SNS parser models with field descriptions and examples using Pydantic's
Field()functionality. This improvement will provide better documentation and metadata for SNS event parsing, following the pattern established in PR #7100.Motivation
Currently, the SNS 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/sns.pyReference events:
Check the sample events in
tests/events/for realistic field values:snsEvent.jsonsnsEventBatch.jsonImplementation Requirements
descriptionfor each field explaining its purpose and usageexamplesshowing realistic AWS SNS 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