Skip to content

Invalid JSON log does not contain initDurationMs/restoreDurationMs #305

@aferrari94

Description

@aferrari94

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

  1. Deploy a Lambda function with log format set to JSON (Monitoring and operations tools → Logging configuration → Log format → JSON)
  2. Run the Power Tuning state machine targeting that function
  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions