如果我设置了一个头X-Amz-Invocation-Type:'Event',调用是异步完成的,但正如亚马逊文档(https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-simple-proxy-for-lambda-output-format)所述,当使用代理Lambda Integration时,lambda函数必须返回这种格式良好的响应:
callback(null, {"statusCode": 200, "body": "results"})由于lambda函数是异步调用的,因此API Gateway永远不会得到应答,然后返回502 Bad Gateway error而不是200OK状态。
下面是swagger配置的摘录:
"/myFunc": {
"post": {
"parameters": [
{
"name": "myparam",
"in": "query",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "200 response"
}
},
"x-amazon-apigateway-request-validator": "Validate query string parameters and headers",
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200"
}
},
"uri": "arn:aws:apigateway:ap-northeast-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:idAccount:function:myFunc/invocations",
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy",
"requestParameters": {
"integration.request.header.X-Amz-Invocation-Type": "'Event'"
}
}
}
}有没有办法让它工作呢?
发布于 2017-12-22 09:19:40
你可以设置一个自定义的lambda集成(没有代理标志)。您将需要配置映射模板以将请求/响应转换为所需的格式。
http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-lambda-non-proxy-integration.html#getting-started-new-lambda
https://stackoverflow.com/questions/45695556
复制相似问题