remotion-dev/remotion · error · RemotionException
Failed to decode final Lambda response: {e}. Raw response: {
Error message
Failed to decode final Lambda response: {e}. Raw response: {result_raw} What it means
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.
Source
Thrown at packages/lambda-python/remotion_lambda/remotionclient.py:491
result_raw: Optional[str] = None # Renamed to avoid confusion with `decoded_result`
decoded_result: Dict[str, Any] = {}
try:
# boto3.client('lambda').invoke returns a dictionary.
# 'Payload' is a StreamingBody object.
response: Dict[str, Any] = client.invoke(FunctionName=function_name, Payload=payload)
streaming_body: StreamingBody = response['Payload']
result_raw = streaming_body.read().decode('utf-8')
parsed_results = self._parse_stream(result_raw)
decoded_result = parsed_results[-1] if parsed_results else {}
except ClientError as e:
raise e
except ParamValidationError as e:
raise RemotionInvalidArgumentException(
f"Invalid Lambda invocation parameters: {e}"
) from e
except json.JSONDecodeError as e:
raise RemotionException(
f"Failed to decode final Lambda response: {e}. Raw response: {result_raw}"
) from e
except UnicodeDecodeError as e:
raise RemotionException(
f"Failed to decode Lambda response payload: {e}"
) from e
if 'errorMessage' in decoded_result:
raise RemotionRenderingOutputError(
f"Lambda function returned an error: {decoded_result['errorMessage']}"
)
if 'type' in decoded_result and decoded_result['type'] == 'error':
raise RemotionRenderingOutputError(
f"Remotion rendering error: {decoded_result['message']}"
)
if 'type' not in decoded_result or decoded_result['type'] != 'success':
raise RemotionRenderingOutputError(View on GitHub (pinned to 78fe4bb3fd)
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.
Example fix
// before - calling Lambda through API Gateway that wraps the response
client.invoke_function_through_apigateway(...)
# after - direct invocation used by RemotionClient
client.render_media(comp, input_props={...}) Defensive patterns
Strategy: try-catch
Try / catch
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 Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse Lambda response stream: {e}
- Failed to decode Lambda response payload: {e}
- Invalid JSON: ${JSON.stringify(decoded)}
- You have multiple buckets ({', '.join(buckets)}) in your S3
- Error serializing InputProps. Check for circular references
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/8e7f36b54c8ff9e0.
Report an issue: GitHub.