AWS应用程序负载平衡器带有Lambda作为目标不起作用

发布于 2025-01-19 06:44:37 字数 1401 浏览 1 评论 0原文

我有一个 AWS Application Load Balancer 配置如下:

  1. 面向接口,ipv4
  2. 侦听 HTTP 协议,端口 80,默认为目标组“lambda-default”;
  3. 目标组“lambda-default”针对 lambda 函数,也称为“lambda-default”;
  4. 安全组将“所有流量”作为入站和出站规则。

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:

  1. interface-facing, ipv4
  2. listens on HTTP protocol, port 80, default to target group "lambda-default";
  3. target group "lambda-default" targets on lambda function also named as "lambda-default";
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2025-01-26 06:44:37

我想出了原因。我创建了另一个安全组,仅允许HTTP协议作为入站规则,并且它有效。

I figured out the cause. I created another security group and only allow http protocol as inbound rule and it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文