简体   繁体   English

如何通过 Application Load Balancer 异步调用 Lambda? (AWS)

[英]How to invoke Lambda asynchronously via Application Load Balancer? (AWS)

Using AWS, wondering if anyone has managed to invoke a lambda asynchronously via an ALB before?使用 AWS,想知道以前是否有人设法通过 ALB 异步调用 lambda?

I've seen API Gateway examples and CLI examples and thought it should be a similar process however nothing has worked so far.我看过 API 网关示例和 CLI 示例,并认为这应该是一个类似的过程,但到目前为止还没有任何效果。 The examples mention passing the invocation type to the header which I have tried ("X-Amzn-Invocation-Type" and "Invocation-Type" with "Event").这些示例提到将调用类型传递给我尝试过的 header(“X-Amzn-Invocation-Type”和“Invocation-Type”与“Event”)。

From Cloudwatch logs I can see the header being passed but it is not the expected behaviour.从 Cloudwatch 日志中,我可以看到 header 正在通过,但这不是预期的行为。

An example, Lambda returns some html with 'Hello World'.例如,Lambda 返回一些带有“Hello World”的 html。

curl -i -X POST -H "X-Amz-Invocation-Type:Event" http://{alb.name}/{path}

Expected response is either 200 or 202预期响应为 200 或 202

Actual response is实际反应是

Server: awselb/2.0
Date: Tue, 25 May 2021 13:06:32 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 246
Connection: keep-alive

<html>
    <head>
    <title>Hello World!</title>
    <style>
    html, body {
    margin: 0; padding: 0;
    font-family: arial; font-weight: 700; font-size: 3em;
    text-align: center;
    }
    </style>
    </head>
    <body>
    <p>Hello World from Lambda</p>
    </body>
    </html>

Cloudwatch logs headers are as follows Cloudwatch 日志头如下

{
    "body": "",
    "requestContext": {
        "elb": {
            "targetGroupArn": "{arn}"
        }
    },
    "queryStringParameters": {},
    "httpMethod": "POST",
    "headers": {
        "x-amz-invocation-type": "Event",
        "x-forwarded-port": "80",
        "x-forwarded-for": "10.0.233.231",
        "accept": "*/*",
        "user-agent": "curl/7.61.1",
        "x-amzn-trace-id": "Root=1-60acf23c-6f1772565f7fbf070f0dd1a9",
        "host": "{alb}",
        "x-forwarded-proto": "http"
    },
    "path": "{path}",
    "isBase64Encoded": "False"
}

Just wondering if anyone has managed to successfully call a lambda asynchronously via an ALB or is that not possible?只是想知道是否有人设法通过 ALB 异步成功地调用 lambda 或者这是不可能的?

Different services invoke AWS Lambda differently:不同的服务调用 AWS Lambda 的方式不同:

https://aws.amazon.com/blogs/architecture/understanding-the-different-ways-to-invoke-lambda-functions/ https://aws.amazon.com/blogs/architecture/understanding-the-different-ways-to-invoke-lambda-functions/

ELB invokes it synchronously. ELB 同步调用它。 That said, the documentation is rather inaccurate.也就是说,文档相当不准确。 API Gateway by default does a synchronous invocation, but with a custom integration and appropriate headers, API Gateway can invoke lambda asynchronously. API 网关默认执行同步调用,但通过自定义集成和适当的标头,API 网关可以异步调用 lambda。 The ability to invoke asynchronously is built into API Gateway. API 网关内置了异步调用的能力。 From the looks of it, this is not present in ELBs like ALB, atleast not in a documented fashion.从外观上看,这在像 ALB 这样的 ELB 中是不存在的,至少没有以记录的方式存在。

There are round about ways but if you are considering those, I guess an API Gateway based solution might make more sense.有很多方法,但如果您正在考虑这些方法,我想基于 API 网关的解决方案可能更有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何异步调用AWS Lambda函数 - How to invoke an AWS Lambda function asynchronously 如何从 aws 中的 lambda function 调用对 a.network load balancer(nlb) vpc 端点的请求 - how to invoke a request to a network load balancer(nlb) vpc endpoint from a lambda function in aws 从另一个 lambda 异步调用 aws lambda - invoke aws lambda from another lambda asynchronously AWS Application Load Balancer- - AWS Application Load Balancer - 如何在kubernetes的aws上创建应用程序负载均衡器 - How to create application load balancer on aws for kubernetes 带有经典负载均衡器的AWS Application负载均衡器 - AWS Application load balancer with classic load balancer 尝试通过AWS Application Load Balancer和Cognito进行身份验证时出现500错误 - 500 error trying to authenticate via AWS Application load balancer and Cognito aws - 通过基于子域的应用程序负载均衡器路由请求 - aws - route request via application load balancer based on subdomain 如何通过 Ingress AWS 应用程序负载均衡器公开 Linkerd Viz Dashboard - How to expose Linkerd Viz Dashboard via Ingress AWS Application Load balancer 如何将 Java Lambda 从 AWS API Gateway 转换为负载均衡器 - How To Convert Java Lambda from AWS API Gateway to Load Balancer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM