Skip to content

Commit c0fbd4b

Browse files
authored
fixing cloudtrail records parsing (#597)
1 parent a1cd963 commit c0fbd4b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

aws/logs_monitoring/parsing.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,20 @@ def s3_handler(event, context, metadata):
198198
# file around 60MB gzipped
199199
data = b"".join(BufferedReader(decompress_stream))
200200

201+
is_cloudtrail_bucket = False
201202
if is_cloudtrail(str(key)):
202203
cloud_trail = json.loads(data)
203-
for event in cloud_trail["Records"]:
204-
# Create structured object and send it
205-
structured_line = merge_dicts(
206-
event, {"aws": {"s3": {"bucket": bucket, "key": key}}}
207-
)
208-
yield structured_line
209-
else:
204+
if cloud_trail.get("Records") is not None:
205+
# only parse as a cloudtrail bucket if we have a Records field to parse
206+
is_cloudtrail_bucket = True
207+
for event in cloud_trail["Records"]:
208+
# Create structured object and send it
209+
structured_line = merge_dicts(
210+
event, {"aws": {"s3": {"bucket": bucket, "key": key}}}
211+
)
212+
yield structured_line
213+
214+
if not is_cloudtrail_bucket:
210215
# Check if using multiline log regex pattern
211216
# and determine whether line or pattern separated logs
212217
data = data.decode("utf-8", errors="ignore")

0 commit comments

Comments
 (0)