Kra*_*zek 6 aws-lambda aws-application-load-balancer
我创建了一个 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
}
Run Code Online (Sandbox Code Playgroud)
这是我在 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
Run Code Online (Sandbox Code Playgroud)
这是我得到的回应
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>
Run Code Online (Sandbox Code Playgroud)
我找不到任何说我们不能从 Lambda 返回非 200 响应的内容,所以我真的不知道......
您还可以在相关的 GitHub 存储库中找到此问题:https : //github.com/aws/aws-lambda-dotnet/issues/507
显然我缺少返回的 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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1427 次 |
| 最近记录: |