Fix parsing for multiline Lambda events logged via logging module
This commit is contained in:
parent
acf7986376
commit
329e55e358
4
index.py
4
index.py
@ -17,7 +17,7 @@ import boto3
|
||||
|
||||
__author__ = "Stefan Reimer"
|
||||
__author_email__ = "stefan@zero-downtime.net"
|
||||
__version__ = "0.9.1"
|
||||
__version__ = "0.9.2"
|
||||
|
||||
# Global alias lookup cache
|
||||
account_aliases = {}
|
||||
@ -229,7 +229,7 @@ def handler(event, context):
|
||||
# "[%(levelname)s]\t%(asctime)s.%(msecs)dZ\t%(aws_request_id)s\t%(message)s\n"
|
||||
_msg = e['message']
|
||||
pattern = r'(?:\[(?P<level>[^\]]*)\])\t(?P<time>.*?)\t(?P<RequestId>\S*?)\t(?P<message>.*)'
|
||||
data = re.match(pattern, e['message'])
|
||||
data = re.match(pattern, e['message'], flags=re.DOTALL)
|
||||
if data:
|
||||
event['level'] = data.group('level')
|
||||
parsed['RequestId'] = data.group('RequestId')
|
||||
|
@ -26,7 +26,7 @@ logging.getLogger("index").setLevel(logging.DEBUG)
|
||||
|
||||
def test_parse():
|
||||
# Test Cloudwatch Logs
|
||||
event = json.loads('{"awslogs": {"data": "H4sICAW8uVwAA3RtcACtU11v00AQfOdXHBaPTb33fZc3p3FLEHFQ4kpAElW2cwkWSRzsM6VU/e9sWpBS1EhF5eUedlczs7Nzt8HGNU22cunNzgXdoB+l0dUwnkyiizg4CarrrauxTBkXUmljgTIsr6vVRV21O+yE2XUTrrNNvshC7xrfWbbbwpfV9mFs4muXbXCOAbUh8JDycPrmfZTGk3TOijzPOHAqnBGFhcwsl1YrzUFbMFQiRNPmTVGXuz3iebn2rm6C7jQ4W1ftoue2C1dfDVcbH8zv2eLvbuv3A7dBuUBSLhRjIEFIzq0VCkBroZQ0RkumjFDSWhCCCZBIai2zmgsqBBL7Eo3x2QZ3pFIyCUpwBDMnfwxD+Kgoqnbry0WXHBo02wZ3Jy9TIJ+pYHyZkHejHhklJH07jqM+oQK4Vvgih+CMTP0XvMCic6+0S/T8P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AnauMM+op0Vxar4m7c68dYpQCr5OQdA3sY606D1YwM7HgvXNLFzsIsVBTBm58EJ5F1k19linZHTvpRs+vnQuODJ6DvvJj8ln35Ii0F4m276cnS1r1z9mny7H6aAgzUGgtSu60jnpvDdvzWQQA1XqJwSRmlJgTF6RMHQEJYpqpg1EsCiKFZrgCc0MALgUTSuj278maBB82V+RRY5WebrcpG/yL4m2U/LEoufexIJDP3LjeRSCkXx+Q1DhdHOGAoNGijnWgqBdmQY1KdygnAePUmWX5LC/zbj4BLT+izbfTm6p3LyT3RF9uOqKP8zwHA5j+5ocZynhp5LRfbTJly0Xecb8qDJALBDNuHG74fxHVm3f3gs4/zNBRbdW/Kp8WryeNzqU/0owPbDV38Ce70icCIGAAA=" } }')
|
||||
index.handler(event, context)
|
||||
|
||||
# Cloudfront Access Logs via S3
|
||||
|
Loading…
Reference in New Issue
Block a user