Description
When a Lambda function has its log format set to JSON (via AWS Advanced Logging Controls), the executor Lambda fails with:
Error: Invalid JSON log does not contain initDurationMs
or
Error: Invalid JSON log does not contain restoreDurationMs
or
Error: Invalid JSON log does not contain billedRestoreDurationMs
Root Cause
After a quickly investigation the problem, apparently, is in lambda/utils.js, the function extractDurationFromJSON performs a strict string check:
if (!log.includes(durationType)) {
throw new Error(`Invalid JSON log does not contain ${durationType}`);
}
This throws an exception when initDurationMs (or restoreDurationMs or billedRestoreDurationMs) is absent from the log:
- initDurationMs — absent on warm start invocations (only present on cold starts)
- restoreDurationMs — absent on non-SnapStart Lambda functions
- billedRestoreDurationMs — absent on non-SnapStart Lambda functions
By contrast, the text log path (extractDurationFromText) handles this gracefully by returning 0 when the regex doesn't match:
if (match == null) return 0;
The JSON path should behave the same way — return 0 instead of throwing.
Steps to Reproduce
- Deploy a Lambda function with log format set to JSON (Monitoring and operations tools → Logging configuration → Log format → JSON)
- Run the Power Tuning state machine targeting that function
- The
executor step fails on the second or subsequent invocations (warm starts) because initDurationMs is not present in the log
Expected Behavior
The extractDurationFromJSON and extractDurationFromText functions should work in the same way giving the same outputs.
The tool should work and complete the happy flow without any exception.
Workaround
Temporarily switch the Lambda's log format from JSON to Text before running the tuning, then switch it back.
Environment
- Power Tuning version: latest (deployed via SAR on 2026-04-22)
- Region: eu-central-1 (tool) / eu-south-1 (target Lambda)
- Lambda log format: JSON (AWS Advanced Logging Controls)
Description
When a Lambda function has its log format set to JSON (via AWS Advanced Logging Controls), the
executorLambda fails with:or
or
Root Cause
After a quickly investigation the problem, apparently, is in
lambda/utils.js, the functionextractDurationFromJSONperforms a strict string check:This throws an exception when
initDurationMs(orrestoreDurationMsorbilledRestoreDurationMs) is absent from the log:By contrast, the text log path (
extractDurationFromText) handles this gracefully by returning0when the regex doesn't match:The JSON path should behave the same way — return
0instead of throwing.Steps to Reproduce
executorstep fails on the second or subsequent invocations (warm starts) becauseinitDurationMsis not present in the logExpected Behavior
The
extractDurationFromJSONandextractDurationFromTextfunctions should work in the same way giving the same outputs.The tool should work and complete the happy flow without any exception.
Workaround
Temporarily switch the Lambda's log format from JSON to Text before running the tuning, then switch it back.
Environment