Skip to content

Commit 439638c

Browse files
feat(parser): add field metadata and examples for CloudWatch models (#7343)
* feat(parser): add field metadata and examples for CloudWatch models * Fix CI --------- Co-authored-by: Leandro Damascena <[email protected]>
1 parent 3808bd2 commit 439638c

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

aws_lambda_powertools/utilities/parser/models/cloudwatch.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,55 @@
1111

1212

1313
class CloudWatchLogsLogEvent(BaseModel):
14-
id: str # noqa AA03 VNE003
15-
timestamp: datetime
16-
message: Union[str, Type[BaseModel]]
14+
id: str = Field(
15+
description="Unique identifier for the log event within the batch.",
16+
examples=["eventId1", "abc123def456"],
17+
)
18+
timestamp: datetime = Field(
19+
description="The time when the event occurred in milliseconds since Jan 1, 1970 00:00:00 UTC.",
20+
examples=[1673779200000],
21+
)
22+
message: Union[str, Type[BaseModel]] = Field(
23+
description="The actual log message string or structured JSON payload emitted by the service or application.",
24+
examples=["This is a sample log message", '{"statusCode":200,"path":"/hello"}'],
25+
)
1726

1827

1928
class CloudWatchLogsDecode(BaseModel):
20-
messageType: str
21-
owner: str
22-
logGroup: str
23-
logStream: str
24-
subscriptionFilters: List[str]
25-
logEvents: List[CloudWatchLogsLogEvent]
26-
policyLevel: Optional[str] = None
29+
messageType: str = Field(
30+
description="The type of CloudWatch Logs message.",
31+
examples=["DATA_MESSAGE", "CONTROL_MESSAGE"],
32+
)
33+
owner: str = Field(description="The AWS account ID of the originating log data.", examples=["123456789012"])
34+
logGroup: str = Field(
35+
description="The name of the log group that contains the log stream.",
36+
examples=["/aws/lambda/my-function", "/aws/apigateway/my-api"],
37+
)
38+
logStream: str = Field(
39+
description="The name of the log stream that stores the log events.",
40+
examples=["2023/01/15/[$LATEST]abcdef1234567890", "i-1234567890abcdef0"],
41+
)
42+
subscriptionFilters: List[str] = Field(
43+
description="List of subscription filter names associated with the log group.",
44+
examples=[["LambdaStream_cloudwatch", "AlertFilter"]],
45+
)
46+
logEvents: List[CloudWatchLogsLogEvent] = Field(
47+
description="Array of log events included in the message.",
48+
examples=[[{"id": "eventId1", "timestamp": 1673779200000, "message": "Sample log line"}]],
49+
)
50+
policyLevel: Optional[str] = Field(
51+
default=None,
52+
description="Optional field specifying the policy level applied to the subscription filter, if present.",
53+
examples=["ACCOUNT", "LOG_GROUP"],
54+
)
2755

2856

2957
class CloudWatchLogsData(BaseModel):
30-
decoded_data: CloudWatchLogsDecode = Field(..., alias="data")
58+
decoded_data: CloudWatchLogsDecode = Field(
59+
...,
60+
alias="data",
61+
description="Decoded CloudWatch log data payload after base64 decoding and decompression.",
62+
)
3163

3264
@field_validator("decoded_data", mode="before")
3365
def prepare_data(cls, value):
@@ -42,4 +74,6 @@ def prepare_data(cls, value):
4274

4375

4476
class CloudWatchLogsModel(BaseModel):
45-
awslogs: CloudWatchLogsData
77+
awslogs: CloudWatchLogsData = Field(
78+
description="Top-level CloudWatch Logs model containing the AWS logs data section.",
79+
)

0 commit comments

Comments
 (0)