【发布时间】:2020-09-12 13:45:30
【问题描述】:
我有一个 python lambda 函数和一个 API Gateway Lambda 代理集成。
python代码返回:
{
"statusCode": str(code),
"body": error if error else result.format(**event),
"headers": {
"Content-Type": "application/json",
**kwargs,
}
}
API Gateway 中的响应如下所示:
Endpoint response body before transformations:
{
"statusCode": "200",
"body": "Some text.",
"headers": {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
"kwarg": "foo"
}
}
2020 年 5 月 25 日星期一 20:18:44 UTC:方法响应标头:{Content-Type=application/json, Access-Control-Allow-Origin=*, Access-Control-Allow-Credentials=true, password=1 , X-Amzn-Trace-Id=Root=1-5ecc2824-c55ec6e1dc79ba1417361345;Sampled=0}
但是,对应用程序的响应在到达客户端时会丢失所有标头。客户端反而收到:
{
"data":"Some text.",
"status":200,
"statusText":"",
"headers":{
"content-length":"10",
"content-type":"application/json"
},
"config":{
"method":"GET",
"headers":{
"Content-Type":"application/json",
"Accept":"application/json"
},
"timeout":0,
"transformRequest":[
null
],
"transformResponse":[
null
],
"url":"https://something.execute-api.region.amazonaws.com/test/page?foo=bar",
"data":""
}
}
我需要改变什么?
提前感谢您的帮助。
【问题讨论】:
-
您是否打印了
kwargs并在 CloudWatch 中进行了验证?
标签: amazon-web-services aws-lambda aws-api-gateway