我已经创建了一个Lambda,它检查一个DynamoDB表是否存在一个记录匹配的主机和请求路径,如果找到,返回一个重定向到匹配的URL。
我的Lambda返回这个响应,但是ALB返回502。
{
"statusCode": 301,
"statusDescription": null,
"headers": {
"Location": "https://www.my-target.co.uk/"
},
"multiValueHeaders": null,
"body": "Redirecting to https://www.my-target.co.uk/",
"isBase64Encoded": false
}这是我在CloudWatch中为Lambda函数找到的日志
START RequestId: 8b5a28f2-c56d-4418-a7b9-66ebe0ba2470 Version: $LATEST
[Information] EMG.ApplicationLoadBalancerRequestHandler: Received: GET /
[Information] EMG.ApplicationLoadBalancerRequestHandler: Processing: my-test.net /
[Information] EMG.RedirectManagers.RedirectTableRedirectManager: Fetching item: my-test.net / from table redirect-table
[Information] EMG.ApplicationLoadBalancerRequestHandler: Found: https://www.target.co.uk/ Permanent
END RequestId: 8b5a28f2-c56d-4418-a7b9-66ebe0ba2470
REPORT RequestId: 8b5a28f2-c56d-4418-a7b9-66ebe0ba2470 Duration: 69.59 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 39 MB 这就是我得到的回应
HTTP/1.1 502
status: 502
Server: awselb/2.0
Date: Thu, 15 Aug 2019 19:13:58 GMT
Content-Type: text/html
Content-Length: 138
Connection: keep-alive
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
</body>
</html>我找不到任何东西说我们不能回复兰博达的非200条回复所以我真的不知道.
您还可以在相关的GitHub repo:https://github.com/aws/aws-lambda-dotnet/issues/507中找到这个问题。
发布于 2019-08-19 19:15:53
显然,我丢失了返回的HTTP响应的必需属性。
这里是AWS文件 (强调雷)的相关部分。
Lambda函数的响应必须包括Base64编码状态、状态代码、状态描述和标头。你可以省略身体。 statusDescription标头必须包含状态代码和原因短语,由单个空格分隔。
修改我的代码,使Lambda的响应符合解决问题的要求。
{
"statusCode": 301,
"statusDescription": "301 Found",
"headers": {
"Location": "https://www.my-target.co.uk/"
},
"multiValueHeaders": null,
"body": "Redirecting to https://www.my-target.co.uk/",
"isBase64Encoded": false
}https://stackoverflow.com/questions/57562352
复制相似问题