使用Amazon Bedrock调用Lambda报错:无法处理Lambda响应
Amazon Bedrock调用Lambda返回响应仍报错的解决方案
问题详情
你通过Amazon Bedrock动作组调用Lambda函数时,Lambda已返回响应,但Bedrock抛出以下错误:
The server encountered an error processing the Lambda response. Check the Lambda response and retry the request
你的Lambda返回内容为:
{'messageVersion': '1.0', 'response': {'actionGroup': 'action-group-quick-start-55acd', 'function': 'connectSQL', 'functionResponse': {'responseBody': [{'total_count': 10000}]}}}
错误原因
Lambda返回的responseBody格式不符合Bedrock的要求:Bedrock要求responseBody必须是键值对对象,而非数组,且需要明确指定输出类型(如text或json)。
修正后的Lambda响应示例
方式1:用text类型包装
{'messageVersion': '1.0', 'response': {'actionGroup': 'action-group-quick-start-55acd', 'function': 'connectSQL', 'functionResponse': {'responseBody': {'text': '{"total_count": 10000}'}}}}
方式2:用json类型包装
{'messageVersion': '1.0', 'response': {'actionGroup': 'action-group-quick-start-55acd', 'function': 'connectSQL', 'functionResponse': {'responseBody': {'json': '{"total_count": 10000}'}}}}
说明
Bedrock动作组对Lambda的响应格式有严格校验,responseBody不能直接传递数组或原始对象,必须包装成text或json类型的键值对结构,确保Bedrock能正确解析返回内容。
内容的提问来源于stack exchange,提问作者sashmi
相关产品推荐
相关产品推荐

