{"record":{"id":"8e7f36b54c8ff9e0","repo":"remotion-dev/remotion","slug":"failed-to-decode-final-lambda-response-e-raw-r","errorCode":null,"errorMessage":"Failed to decode final Lambda response: {e}. Raw response: {result_raw}","messagePattern":"Failed to decode final Lambda response: (.+?)\\. Raw response: (.+?)","errorType":"exception","errorClass":"RemotionException","httpStatus":null,"severity":"error","filePath":"packages/lambda-python/remotion_lambda/remotionclient.py","lineNumber":491,"sourceCode":"        result_raw: Optional[str] = None # Renamed to avoid confusion with `decoded_result`\n        decoded_result: Dict[str, Any] = {}\n\n        try:\n            # boto3.client('lambda').invoke returns a dictionary.\n            # 'Payload' is a StreamingBody object.\n            response: Dict[str, Any] = client.invoke(FunctionName=function_name, Payload=payload)\n            streaming_body: StreamingBody = response['Payload']\n            result_raw = streaming_body.read().decode('utf-8')\n            parsed_results = self._parse_stream(result_raw)\n            decoded_result = parsed_results[-1] if parsed_results else {}\n        except ClientError as e:\n            raise e\n        except ParamValidationError as e:\n            raise RemotionInvalidArgumentException(\n                f\"Invalid Lambda invocation parameters: {e}\"\n            ) from e\n        except json.JSONDecodeError as e:\n            raise RemotionException(\n                f\"Failed to decode final Lambda response: {e}. Raw response: {result_raw}\"\n            ) from e\n        except UnicodeDecodeError as e:\n            raise RemotionException(\n                f\"Failed to decode Lambda response payload: {e}\"\n            ) from e\n\n        if 'errorMessage' in decoded_result:\n            raise RemotionRenderingOutputError(\n                f\"Lambda function returned an error: {decoded_result['errorMessage']}\"\n            )\n\n        if 'type' in decoded_result and decoded_result['type'] == 'error':\n            raise RemotionRenderingOutputError(\n                f\"Remotion rendering error: {decoded_result['message']}\"\n            )\n        if 'type' not in decoded_result or decoded_result['type'] != 'success':\n            raise RemotionRenderingOutputError(","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/lambda-python/remotion_lambda/remotionclient.py#L473-L509","documentation":"Raised after the streamed Lambda response has been parsed into chunks but the FINAL chunk is not valid JSON (json.JSONDecodeError on the last parsed object). The raw response text is included in the message. This indicates the terminal Lambda payload is corrupt, distinct from a partial mid-stream chunk.","triggerScenarios":"The Lambda response ends with a non-JSON terminator (e.g. a plain-text error from the runtime, an HTML page from a proxy, or an empty response); _parse_stream succeeded on intermediate chunks but the final selection is malformed.","commonSituations":"Lambda returns an empty Payload when the function crashed before writing output; API Gateway/proxy wraps the response; version mismatch where the function emits an unexpected terminal schema; binary or encoded responses that bypass JSON.","solutions":["Inspect the raw response text included in the error message to identify the corruption source.","Check CloudWatch Logs for the Lambda function for crashes or runtime errors.","Bypass API Gateway/proxy by invoking the function directly.","Upgrade both the Python client and the Lambda function to matching Remotion versions."],"exampleFix":"// before - calling Lambda through API Gateway that wraps the response\nclient.invoke_function_through_apigateway(...)\n\n# after - direct invocation used by RemotionClient\nclient.render_media(comp, input_props={...})","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\\n    result = client.render_media(...)\\nexcept RemotionException as e:\\n    raw = str(e)  # contains raw response text\\n    log.error('Lambda final decode failed. raw=%s', raw)\\n    raise","preventionTips":["Invoke the function directly, not via API Gateway.","Keep Python client and Lambda function on matching Remotion versions.","Inspect CloudWatch Logs to confirm the function actually emits a final JSON chunk."],"tags":["python","lambda","json","response-decoding","aws"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}