AWS应用程序负载平衡器带有Lambda作为目标不起作用
我有一个 AWS Application Load Balancer 配置如下:
- 面向接口,ipv4
- 侦听 HTTP 协议,端口 80,默认为目标组“lambda-default”;
- 目标组“lambda-default”针对 lambda 函数,也称为“lambda-default”;
- 安全组将“所有流量”作为入站和出站规则。
lambda 函数“lambda-default”只有一些测试代码:
exports.handler = async (event) => {
console.log('=========default being called=========')
console.log(JSON.stringify(event))
const response = {
"statusCode": 200,
"statusDescription": "200 OK",
"isBase64Encoded": false,
"headers": {
"Content-Type": "text/html"
},
"body": "<h1>Hello from Lambda!</h1>"
}
return response;
};
我在浏览器中以及使用curl 在 CLI 中输入了我的 alb 的 DNS 名称,但没有一个起作用。它不返回任何内容。卷曲请求返回类似:curl: (52) Empty returned from server
。
我检查了 alb 的“监视”选项卡,那里什么也没有,似乎 alb 根本没有收到任何请求。这是一个屏幕截图:alb 监视器选项卡屏幕截图
我也检查了 lambda 日志。日志中的所有请求均由“ELB-HealthChecker/2.0”触发。 alb 没有触发任何请求。
我检查了安全组。它允许所有流量。不应该是这个原因。这是一个屏幕截图: 安全组截图
我还查看了一些教程视频,例如 https://www.youtube.com/watch?v=56a-wAeEl7E 他们正在做同样的事情。唯一的区别是它们在 HTTPS 端口 443 上有额外的侦听器。但我不认为这是原因。
那么我在这里错过了什么吗?
I have a AWS Application Load Balancer configured as such:
- interface-facing, ipv4
- listens on HTTP protocol, port 80, default to target group "lambda-default";
- target group "lambda-default" targets on lambda function also named as "lambda-default";
- security group has "all traffic" as inbound and outbound rules.
The lambda function "lambda-default" has nothing but some test code:
exports.handler = async (event) => {
console.log('=========default being called=========')
console.log(JSON.stringify(event))
const response = {
"statusCode": 200,
"statusDescription": "200 OK",
"isBase64Encoded": false,
"headers": {
"Content-Type": "text/html"
},
"body": "<h1>Hello from Lambda!</h1>"
}
return response;
};
I hit the DNS name of my alb in the browser, as well as in CLI using curl, none worked. It doesn't return anything. curl request returns something like: curl: (52) Empty reply from server
.
I checked "monitor" tab for alb, nothing there, seems like alb didn't get any requests at all. Here's a screenshot: alb monitor tab screenshot
I checked logs for lambda as well. All the requests in the logs are triggered by "ELB-HealthChecker/2.0". There's no requests triggered by alb.
I checked security group. It allows all traffic. It shouldn't be the cause. Here's a screenshot:
security group screenshot
I also checked some tutorial videos, e.g. https://www.youtube.com/watch?v=56a-wAeEl7E They're doing the same thing. The only difference is they have additional listener on HTTPS port 443. But i don't think that's the reason.
So am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了原因。我创建了另一个安全组,仅允许HTTP协议作为入站规则,并且它有效。
I figured out the cause. I created another security group and only allow http protocol as inbound rule and it works.