本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
开启调试消息
在网关开发期间,您可以开启调试消息以返回有关目标配置问题的详细信息,包括 lambda 函数错误、出口授权器错误、目标规范参数验证错误。开启调试消息后,如果调用网关时出现问题,响应将返回消息以帮助您进行调试。
要打开调试消息,请执行以下操作之一:
-
如果您使用 AgentCore CLI 创建网关,则调试会自动开启。
-
如果您使用 AWS 管理控制台创建网关,则默认情况下调试处于启用状态。该选项位于 “网关详细信息” 部分的 “其他配置” 下。
-
如果您使用 AWS CLI 或 S AWS DK,请将该
exceptionLevel值设置为发出CreateGateway或UpdateGateway请求DEBUG时的值。
完成网关调试后,您可以更新网关以关闭调试消息,这样发送给最终用户的消息仅显示未指定的内部错误。
要关闭调试消息,请执行以下操作之一:
-
在 AWS 管理控制台中,在创建或编辑网关时展开 “网关详细信息” 部分中的其他配置,然后取消选中 “异常级别调试” 旁边的复选框。
-
在 AWS CLI 或 S AWS DK 中,
UpdateGateway发出CreateGateway或请求关闭调试时省略该exceptionLevel字段。
开启和关闭调试的网关响应示例
例如,假设用户没有权限调用网关所针对的 Lambda 函数。调用此函数的请求将返回不同的消息,具体取决于调试是开启还是关闭:
-
调试开启 -将在内容
text字段和响应字段中返回详细的错误消息,如以下示例所示:_meta{ "jsonrpc": "2.0", "id": 24, "result": { "content": [ { "type": "text", "text": "Access denied while invoking Lambda function arn:aws:lambda:us-west-2:123456789012:function:TestGatewayLambda. Check the permissions on the Lambda function and Gateway execution role, and retry the request." } ], "_meta": { "debug": { "type": "text", "text": "Access denied while invoking Lambda function arn:aws:lambda:us-west-2:123456789012:function:TestGatewayLambda. Check the permissions on the Lambda function and Gateway execution role, and retry the request." } }, "isError": true } } -
调试关闭 — 响应的内容
text字段中将返回一条通用错误消息,如以下示例所示:{ "jsonrpc": "2.0", "id": 24, "result": { "content": [ { "type": "text", "text": "An internal error occurred. Please retry later." } ], "isError": true } }