{"record":{"id":"8f06c9a946f02923","repo":"remotion-dev/remotion","slug":"failed-to-decode-lambda-response-payload-e","errorCode":null,"errorMessage":"Failed to decode Lambda response payload: {e}","messagePattern":"Failed to decode Lambda response payload: (.+?)","errorType":"exception","errorClass":"RemotionException","httpStatus":null,"severity":"error","filePath":"packages/lambda-python/remotion_lambda/remotionclient.py","lineNumber":495,"sourceCode":"            # 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(\n                f\"Unexpected Lambda response format: {result_raw}\"\n            )\n\n        return decoded_result","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/lambda-python/remotion_lambda/remotionclient.py#L477-L513","documentation":"Raised when the raw Lambda Payload bytes cannot be decoded as UTF-8 (UnicodeDecodeError). Indicates the response body contains bytes outside the UTF-8 range, which the Remotion protocol does not expect.","triggerScenarios":"Lambda returns binary data, a non-UTF-8 encoded error page, or a corrupted byte stream from a truncated response; the streaming body read() yields partial bytes due to a network drop.","commonSituations":"Network interruption truncating multi-byte sequences; a proxy injecting a gzip/binary error page; Lambda runtime returning an unexpected binary artifact; mismatched encoding between function and client.","solutions":["Inspect the UnicodeDecodeError position in __cause__ to confirm truncation vs binary content.","Check CloudWatch Logs for the Lambda function for crashes that produced a binary error page.","Retry the render; transient truncation often clears on a fresh invocation.","If persistently binary, capture raw bytes via the AWS CLI to confirm the function's actual output."],"exampleFix":"// before - flaky network truncates the streaming body mid-multibyte\nclient.render_media(...)\n\n# after - retry transient decode failures\nfrom botocore.exceptions import ClientError\nfor attempt in range(3):\n    try:\n        client.render_media(...)\n        break\n    except UnicodeDecodeError:\n        if attempt == 2: raise","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        result = client.render_media(...)\n        break\n    except RemotionException as e:\n        if 'Failed to decode Lambda response payload' in str(e) and attempt < 2:\n            sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Treat transient UnicodeDecodeError as a sign of network truncation and retry.","Check CloudWatch Logs for crashes that produce binary error pages.","Avoid proxies that inject binary/gzip error pages into the Lambda response."],"tags":["python","lambda","unicode","response-decoding","aws"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}