alexcasalboni / aws-lambda-power-tuning

AWS Lambda Power Tuning is an open-source tool that can help you visualize and fine-tune the memory/power configuration of Lambda functions. It runs in your own AWS account - powered by AWS Step Functions - and it supports three optimization strategies: cost, speed, and balanced.
Apache License 2.0
5.27k stars 362 forks source link

Error in Parsing Lambda Result Logs #253

Open RomanOttGmx opened 1 week ago

RomanOttGmx commented 1 week ago

I get an error during executing state machine in the executor lambda.

Logs from Execute Lambda: { "errorType": "SyntaxError", "errorMessage": "Unexpected end of JSON input", "stack": [ "SyntaxError: Unexpected end of JSON input", " at JSON.parse ()", " at /var/task/utils.js:552:54", " at Array.map ()", " at module.exports.extractDurationFromJSON (/var/task/utils.js:552:35)", " at module.exports.extractDuration (/var/task/utils.js:529:22)", " at /var/task/utils.js:473:22", " at Array.map ()", " at module.exports.parseLogAndExtractDurations (/var/task/utils.js:470:17)", " at computeStatistics (/var/task/executor.js:180:29)", " at module.exports.handler (/var/task/executor.js:71:12)" ] }

Because the result inherits empty lines.

In utils.js there is a module function: module.exports.extractDurationFromJSON = (log) => {

const lines = log.split('\n').filter((line) => line.startsWith('{')).map((line) => {

Replacing it with: const lines = log.split('\n').filter(line => line.trim() !== '').map((line) => JSON.parse(line));

it works. Best Regards