AWS lambda api 网关错误“格式错误的 Lambda 代理响应" [英] AWS lambda api gateway error "Malformed Lambda proxy response"

查看:34
本文介绍了AWS lambda api 网关错误“格式错误的 Lambda 代理响应"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 AWS lambda 设置一个 hello world 示例并通过 api 网关为其提供服务.我单击了创建 Lambda 函数",它设置了 api 网关并选择了空白函数选项.我添加了在 上找到的 lambda 函数AWS 网关入门指南:

I am trying to set up a hello world example with AWS lambda and serving it through api gateway. I clicked the "Create a Lambda Function", which set up the api gatway and selected the Blank Function option. I added the lambda function found on AWS gateway getting started guide:

exports.handler = function(event, context, callback) {
  callback(null, {"Hello":"World"});  // SUCCESS with message
};

问题是当我向它发出 GET 请求时,它返回 502 响应 { "message": "Internal server error" }.并且日志显示由于配置错误,执行失败:Lambda 代理响应格式错误".

The issue is that when I make a GET request to it, it's returning back a 502 response { "message": "Internal server error" }. And the logs say "Execution failed due to configuration error: Malformed Lambda proxy response".

推荐答案

通常,当您看到 Malformed Lambda proxy response 时,表示您的 Lambda 函数的响应与格式 API Gateway 不匹配正在期待,像这样

Usually, when you see Malformed Lambda proxy response, it means your response from your Lambda function doesn't match the format API Gateway is expecting, like this

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "body": "..."
}

如果您没有使用 Lambda 代理集成,您可以登录 API Gateway 控制台并取消选中 Lambda 代理集成复选框.

If you are not using Lambda proxy integration, you can login to API Gateway console and uncheck the Lambda proxy integration checkbox.

此外,如果您看到间歇性Malformed Lambda proxy response,这可能意味着对您的 Lambda 函数的请求已被 Lambda 限制,您需要请求增加 Lambda 上的并发执行限制功能.

Also, if you are seeing intermittent Malformed Lambda proxy response, it might mean the request to your Lambda function has been throttled by Lambda, and you need to request a concurrent execution limit increase on the Lambda function.

这篇关于AWS lambda api 网关错误“格式错误的 Lambda 代理响应"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆