From b1058b46011a13ed6f0b224b2759a40102932b92 Mon Sep 17 00:00:00 2001 From: Aryahi Date: Mon, 8 Sep 2025 23:34:26 +0530 Subject: [PATCH 1/2] feat(parser): add field metadata and examples for CloudWatch models --- .../utilities/parser/models/cloudwatch.py | 73 ++++++++++++++++--- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/aws_lambda_powertools/utilities/parser/models/cloudwatch.py b/aws_lambda_powertools/utilities/parser/models/cloudwatch.py index d09b17133a9..cac60def8e9 100644 --- a/aws_lambda_powertools/utilities/parser/models/cloudwatch.py +++ b/aws_lambda_powertools/utilities/parser/models/cloudwatch.py @@ -11,23 +11,70 @@ class CloudWatchLogsLogEvent(BaseModel): - id: str # noqa AA03 VNE003 - timestamp: datetime - message: Union[str, Type[BaseModel]] + id: str = Field( + description="Unique identifier for the log event within the batch.", + examples=["eventId1", "abc123def456"] + ) + timestamp: datetime = Field( + description="The time when the event occurred, expressed as the number of milliseconds since Jan 1, 1970 00:00:00 UTC.", + examples=[1673779200000] + ) + message: Union[str, Type[BaseModel]] = Field( + description="The actual log message string or structured JSON payload emitted by the service or application.", + examples=[ + "This is a sample log message", + '{"statusCode":200,"path":"/hello"}' + ] + ) class CloudWatchLogsDecode(BaseModel): - messageType: str - owner: str - logGroup: str - logStream: str - subscriptionFilters: List[str] - logEvents: List[CloudWatchLogsLogEvent] - policyLevel: Optional[str] = None + 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"] + ) + logGroup: str = Field( + description="The name of the log group that contains the log stream.", + examples=["/aws/lambda/my-function", "/aws/apigateway/my-api"] + ) + logStream: str = Field( + description="The name of the log stream that stores the log events.", + examples=[ + "2023/01/15/[$LATEST]abcdef1234567890", + "i-1234567890abcdef0" + ] + ) + subscriptionFilters: List[str] = Field( + description="List of subscription filter names associated with the log group.", + examples=[["LambdaStream_cloudwatch", "AlertFilter"]] + ) + logEvents: List[CloudWatchLogsLogEvent] = Field( + description="Array of log events included in the message.", + examples=[[ + { + "id": "eventId1", + "timestamp": 1673779200000, + "message": "Sample log line" + } + ]] + ) + policyLevel: Optional[str] = Field( + default=None, + description="Optional field specifying the policy level applied to the subscription filter, if present.", + examples=["ACCOUNT", "LOG_GROUP"] + ) class CloudWatchLogsData(BaseModel): - decoded_data: CloudWatchLogsDecode = Field(..., alias="data") + decoded_data: CloudWatchLogsDecode = Field( + ..., + alias="data", + description="Decoded CloudWatch log data payload after base64 decoding and decompression." + ) @field_validator("decoded_data", mode="before") def prepare_data(cls, value): @@ -42,4 +89,6 @@ def prepare_data(cls, value): class CloudWatchLogsModel(BaseModel): - awslogs: CloudWatchLogsData + awslogs: CloudWatchLogsData = Field( + description="Top-level CloudWatch Logs model containing the AWS logs data section." + ) From 11e43c828c8ef5ef7c726b596d42f2a5fdcdfd11 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Tue, 9 Sep 2025 13:59:05 +0100 Subject: [PATCH 2/2] Fix CI --- .../utilities/parser/models/cloudwatch.py | 41 ++++++------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/aws_lambda_powertools/utilities/parser/models/cloudwatch.py b/aws_lambda_powertools/utilities/parser/models/cloudwatch.py index cac60def8e9..6c3d25e1727 100644 --- a/aws_lambda_powertools/utilities/parser/models/cloudwatch.py +++ b/aws_lambda_powertools/utilities/parser/models/cloudwatch.py @@ -13,59 +13,44 @@ class CloudWatchLogsLogEvent(BaseModel): id: str = Field( description="Unique identifier for the log event within the batch.", - examples=["eventId1", "abc123def456"] + examples=["eventId1", "abc123def456"], ) timestamp: datetime = Field( - description="The time when the event occurred, expressed as the number of milliseconds since Jan 1, 1970 00:00:00 UTC.", - examples=[1673779200000] + description="The time when the event occurred in milliseconds since Jan 1, 1970 00:00:00 UTC.", + examples=[1673779200000], ) message: Union[str, Type[BaseModel]] = Field( description="The actual log message string or structured JSON payload emitted by the service or application.", - examples=[ - "This is a sample log message", - '{"statusCode":200,"path":"/hello"}' - ] + examples=["This is a sample log message", '{"statusCode":200,"path":"/hello"}'], ) 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"] + examples=["DATA_MESSAGE", "CONTROL_MESSAGE"], ) + owner: str = Field(description="The AWS account ID of the originating log data.", examples=["123456789012"]) logGroup: str = Field( description="The name of the log group that contains the log stream.", - examples=["/aws/lambda/my-function", "/aws/apigateway/my-api"] + examples=["/aws/lambda/my-function", "/aws/apigateway/my-api"], ) logStream: str = Field( description="The name of the log stream that stores the log events.", - examples=[ - "2023/01/15/[$LATEST]abcdef1234567890", - "i-1234567890abcdef0" - ] + examples=["2023/01/15/[$LATEST]abcdef1234567890", "i-1234567890abcdef0"], ) subscriptionFilters: List[str] = Field( description="List of subscription filter names associated with the log group.", - examples=[["LambdaStream_cloudwatch", "AlertFilter"]] + examples=[["LambdaStream_cloudwatch", "AlertFilter"]], ) logEvents: List[CloudWatchLogsLogEvent] = Field( description="Array of log events included in the message.", - examples=[[ - { - "id": "eventId1", - "timestamp": 1673779200000, - "message": "Sample log line" - } - ]] + examples=[[{"id": "eventId1", "timestamp": 1673779200000, "message": "Sample log line"}]], ) policyLevel: Optional[str] = Field( default=None, description="Optional field specifying the policy level applied to the subscription filter, if present.", - examples=["ACCOUNT", "LOG_GROUP"] + examples=["ACCOUNT", "LOG_GROUP"], ) @@ -73,7 +58,7 @@ class CloudWatchLogsData(BaseModel): decoded_data: CloudWatchLogsDecode = Field( ..., alias="data", - description="Decoded CloudWatch log data payload after base64 decoding and decompression." + description="Decoded CloudWatch log data payload after base64 decoding and decompression.", ) @field_validator("decoded_data", mode="before") @@ -90,5 +75,5 @@ def prepare_data(cls, value): class CloudWatchLogsModel(BaseModel): awslogs: CloudWatchLogsData = Field( - description="Top-level CloudWatch Logs model containing the AWS logs data section." + description="Top-level CloudWatch Logs model containing the AWS logs data section.", )