Created
August 12, 2020 18:32
-
-
Save aada/021f7b0eaa1319fd42cc50bad71d0b51 to your computer and use it in GitHub Desktop.
parse cloudwatch lambda logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const lambda_report_pattern = /REPORT RequestId: ([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\s{1,}Duration: (\d{1,}.\d{1,}) ms\s{1,}Billed Duration: (\d{1,}) ms\s{1,}Memory Size: (\d{1,}) MB\s{1,}Max Memory Used: (\d{1,}) MB/; | |
| const lambda_start_pattern = /START RequestId: ([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\s{1,}Version: /; | |
| const lambda_end_pattern = /END RequestId: ([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})/; | |
| const lambda_report_example = `REPORT RequestId: 4af5ccd9-fef7-11e8-8de1-bfd74775c3f5 Duration: 38.07 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 32 MB`; | |
| const lambda_start_example = `START RequestId: 698e4612-06da-43ee-93d1-623b6946bc24 Version: $LATEST`; | |
| const lambda_end_example = `END RequestId: 698e4612-06da-43ee-93d1-623b6946bc24`; | |
| if (lambda_report_pattern.test(lambda_report_example)) { | |
| console.log("lambda_report_pattern found"); | |
| const tokens = lambda_report_example.split(" "); | |
| const RequestId = tokens[2]; | |
| const Duration = parseFloat(tokens[4]); | |
| const Billed_Duration = parseFloat(tokens[8]); | |
| const Memory_Size = parseFloat(tokens[12]); | |
| const Max_Memory_Used = parseFloat(tokens[17]); | |
| console.log({ | |
| RequestId, | |
| Duration, | |
| Billed_Duration, | |
| Memory_Size, | |
| Max_Memory_Used | |
| }); | |
| } | |
| if (lambda_start_pattern.test(lambda_start_example)) { | |
| console.log("lambda_start_pattern found"); | |
| const tokens = lambda_start_example.split(" "); | |
| const RequestId = tokens[2]; | |
| const Version = tokens[4]; | |
| console.log({ | |
| RequestId, | |
| Version | |
| }); | |
| } | |
| if (lambda_end_pattern.test(lambda_end_example)) { | |
| console.log("lambda_end_pattern found"); | |
| const tokens = lambda_end_example.split(" "); | |
| const RequestId = tokens[2]; | |
| console.log({ | |
| RequestId | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment