File tree 4 files changed +10
-5
lines changed
aws_lambda_powertools/utilities/parser
4 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 1
1
from .base import BaseEnvelope
2
- from .cloudwatch import CloudatchEnvelope
2
+ from .cloudwatch import CloudatchLogsEnvelope
3
3
from .dynamodb import DynamoDBStreamEnvelope
4
4
from .event_bridge import EventBridgeEnvelope
5
5
from .sns import SnsEnvelope
6
6
from .sqs import SqsEnvelope
7
7
8
8
__all__ = [
9
- "CloudatchEnvelope " ,
9
+ "CloudatchLogsEnvelope " ,
10
10
"DynamoDBStreamEnvelope" ,
11
11
"EventBridgeEnvelope" ,
12
12
"SnsEnvelope" ,
Original file line number Diff line number Diff line change 8
8
logger = logging .getLogger (__name__ )
9
9
10
10
11
- class CloudatchEnvelope (BaseEnvelope ):
11
+ class CloudatchLogsEnvelope (BaseEnvelope ):
12
12
"""Cloudatch Envelope to extract a List of log records.
13
13
14
14
The record's body parameter is a string (after being base64 decoded and gzipped),
Original file line number Diff line number Diff line change 1
1
import base64
2
2
import json
3
+ import logging
3
4
import zlib
4
5
from datetime import datetime
5
6
from typing import List
6
7
7
8
from pydantic import BaseModel , Field , validator
8
9
10
+ logger = logging .getLogger (__name__ )
11
+
9
12
10
13
class CloudWatchLogsLogEvent (BaseModel ):
11
14
id : str # noqa AA03 VNE003
@@ -28,9 +31,11 @@ class CloudWatchLogsData(BaseModel):
28
31
@validator ("decoded_data" , pre = True )
29
32
def prepare_data (cls , value ):
30
33
try :
34
+ logger .debug ("Decoding base64 cloudwatch log data before parsing" )
31
35
payload = base64 .b64decode (value )
36
+ logger .debug ("Decompressing cloudwatch log data before parsing" )
32
37
uncompressed = zlib .decompress (payload , zlib .MAX_WBITS | 32 )
33
- return json .loads (uncompressed .decode ("UTF -8" ))
38
+ return json .loads (uncompressed .decode ("utf -8" ))
34
39
except Exception :
35
40
raise ValueError ("unable to decompress data" )
36
41
Original file line number Diff line number Diff line change 12
12
from tests .functional .parser .utils import load_event
13
13
14
14
15
- @event_parser (model = MyCloudWatchBusiness , envelope = envelopes .CloudatchEnvelope )
15
+ @event_parser (model = MyCloudWatchBusiness , envelope = envelopes .CloudatchLogsEnvelope )
16
16
def handle_cloudwatch_logs (event : List [MyCloudWatchBusiness ], _ : LambdaContext ):
17
17
assert len (event ) == 1
18
18
log : MyCloudWatchBusiness = event [0 ]
You can’t perform that action at this time.
0 commit comments