remotion-dev/remotion · error · RemotionException

Failed to parse Lambda response stream: {e}

Error message

Failed to parse Lambda response stream: {e}

What it means

Raised inside _parse_stream when one of the JSON objects extracted from the Lambda response stream cannot be decoded. The Lambda returns concatenated JSON chunks (progress + final result); each chunk must be individually valid JSON. The offending raw chunk is logged at error level before the raise.

Source

Thrown at packages/lambda-python/remotion_lambda/remotionclient.py:465

                if depth == 0:
                    start_index = i
                depth += 1
            elif char == '}':
                depth -= 1
                if depth == 0:
                    objects.append(input_string[start_index : i + 1])
        return objects

    def _parse_stream(self, stream: str) -> List[Dict[str, Any]]: # Added type hints
        """Parses a stream of concatenated JSON objects."""
        json_objects = self._find_json_objects(stream)
        parsed_objects: List[Dict[str, Any]] = []
        for obj_str in json_objects: # Renamed obj to obj_str to avoid confusion with parsed obj
            try:
                parsed_objects.append(json.loads(obj_str))
            except json.JSONDecodeError as e:
                logger.error("Failed to decode JSON object from stream: %s", obj_str)
                raise RemotionException(
                    f"Failed to parse Lambda response stream: {e}"
                ) from e
        return parsed_objects

    def _invoke_lambda(self, function_name: str, payload: str) -> Dict[str, Any]: # Added type hints
        """Invokes the Remotion Lambda function and parses its response."""
        client = self._create_lambda_client()
        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 {}

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Check CloudWatch Logs for the Lambda function to see the raw response and any crash.
  2. Increase Lambda memory/timeout if the render is hitting resource limits and truncating output.
  3. Ensure you are calling the function directly (not via API Gateway) so the raw streamed response is preserved.
  4. Update the Python client and the Lambda function to matching Remotion versions.

Example fix

// before - lambda function times out mid-render
client.render_media(comp, input_props={'huge': 'data'})  # truncates response

# after
# bump Lambda memory/timeout
aws lambda update-function-configuration --function-name remotion-render-... --memory-size 2048 --timeout 900
client.render_media(comp, input_props={'huge': 'data'})
Defensive patterns

Strategy: retry

Try / catch

from time import sleep
for attempt in range(3):
    try:
        result = client.render_media(...)
        break
    except RemotionException as e:
        if 'Failed to parse Lambda response stream' in str(e) and attempt < 2:
            sleep(2 ** attempt)
            continue
        raise

Prevention

When it happens

Trigger: Lambda returns a partial/truncated chunk due to a network interruption or a function timeout that cut the response mid-object; an unexpected non-JSON error page from an API Gateway/proxy; a malformed chunk produced by a Lambda runtime crash.

Common situations: Lambda hits the 15-minute timeout and the response is truncated; an upstream proxy injects HTML/JSON error text; cold-start crashes emit stack traces mixed with JSON; mismatched Remotion Lambda version emitting an unexpected schema.

Understand the failure class

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/680de9213769f9e1. Report an issue: GitHub.