File tree Expand file tree Collapse file tree 4 files changed +10
-5
lines changed
aws_lambda_powertools/utilities/parser Expand file tree Collapse file tree 4 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 11from .base import BaseEnvelope
2- from .cloudwatch import CloudatchEnvelope
2+ from .cloudwatch import CloudatchLogsEnvelope
33from .dynamodb import DynamoDBStreamEnvelope
44from .event_bridge import EventBridgeEnvelope
55from .sns import SnsEnvelope
66from .sqs import SqsEnvelope
77
88__all__ = [
9- "CloudatchEnvelope " ,
9+ "CloudatchLogsEnvelope " ,
1010 "DynamoDBStreamEnvelope" ,
1111 "EventBridgeEnvelope" ,
1212 "SnsEnvelope" ,
Original file line number Diff line number Diff line change 88logger = logging .getLogger (__name__ )
99
1010
11- class CloudatchEnvelope (BaseEnvelope ):
11+ class CloudatchLogsEnvelope (BaseEnvelope ):
1212 """Cloudatch Envelope to extract a List of log records.
1313
1414 The record's body parameter is a string (after being base64 decoded and gzipped),
Original file line number Diff line number Diff line change 11import base64
22import json
3+ import logging
34import zlib
45from datetime import datetime
56from typing import List
67
78from pydantic import BaseModel , Field , validator
89
10+ logger = logging .getLogger (__name__ )
11+
912
1013class CloudWatchLogsLogEvent (BaseModel ):
1114 id : str # noqa AA03 VNE003
@@ -28,9 +31,11 @@ class CloudWatchLogsData(BaseModel):
2831 @validator ("decoded_data" , pre = True )
2932 def prepare_data (cls , value ):
3033 try :
34+ logger .debug ("Decoding base64 cloudwatch log data before parsing" )
3135 payload = base64 .b64decode (value )
36+ logger .debug ("Decompressing cloudwatch log data before parsing" )
3237 uncompressed = zlib .decompress (payload , zlib .MAX_WBITS | 32 )
33- return json .loads (uncompressed .decode ("UTF -8" ))
38+ return json .loads (uncompressed .decode ("utf -8" ))
3439 except Exception :
3540 raise ValueError ("unable to decompress data" )
3641
Original file line number Diff line number Diff line change 1212from tests .functional .parser .utils import load_event
1313
1414
15- @event_parser (model = MyCloudWatchBusiness , envelope = envelopes .CloudatchEnvelope )
15+ @event_parser (model = MyCloudWatchBusiness , envelope = envelopes .CloudatchLogsEnvelope )
1616def handle_cloudwatch_logs (event : List [MyCloudWatchBusiness ], _ : LambdaContext ):
1717 assert len (event ) == 1
1818 log : MyCloudWatchBusiness = event [0 ]
You can’t perform that action at this time.
0 commit comments