如何异步调用AWS Lambda函数 [英] How to invoke an AWS Lambda function asynchronously
问题描述
有人知道异步调用而不是同步调用Amazon AWS Lambda函数的当前正确方法吗?
Does anyone know the current and correct way to invoke Amazon AWS Lambda functions asynchronously instead of synchronously?
AWS Java SDK中的InvokeAsync API仍然可用,但标记为已弃用,它们建议您使用Invoke API.我不知道为什么他们会强迫我们使用同步.我有一个Web前端,可以调度一些批处理作业.我不能指望前端在等待响应的同时保持几分钟的连接打开状态(实际上是在处理大约4-5分钟后通过电子邮件发送给他们).
The InvokeAsync API in the AWS Java SDK is still available but marked as deprecated and they suggest you use use the Invoke API. I can't figure out why they would be forcing us to using sync. I have a web frontend that dispatches some batch jobs. I can't expect the frontend to keep a connection open for several minutes while it waits for the response (which is actually e-mailed to them after about 4-5 minutes of processing).
理想情况下,我正在尝试找出如何使用其API端点而不是Java SDK来执行此操作,因为我在后端运行的环境(GAE)不支持AWS对HttpClient的使用.
Ideally I'm trying to figure out how to do this with their API Endpoints rather than the Java SDK because the environment (GAE) that I'm running my backend in doesn't support AWS's use of HttpClient.
推荐答案
I'm looking at the latest API docs here, and it looks like only AWSLambdaAsyncClient.invokeAsyncAsync()
is deprecated. The AWSLambdaAsyncClient.invokeAsync()
method is not marked as deprecated. It looks like they are just doing some code cleanup by removing the need for the InvokeAsyncRequest
and InvokeAsyncResult
classes and the extra invokeAsyncAsync()
methods.
您应该能够使用AWSLambdaAsyncClient.invokeAsync()
方法,该方法使用InvokeRequest
并返回InvokeResult
.您可能必须将InvokeRequest
上的InvocationType
设置为InvocationType.Event
.如果您使用的是异步客户端,目前尚不清楚是否需要.
You should be able to use the AWSLambdaAsyncClient.invokeAsync()
method which uses InvokeRequest
and returns InvokeResult
. You might have to set the InvocationType
on the InvokeRequest
to InvocationType.Event
. It's not clear if that's needed if you are using the Async client.
关于不使用SDK异步调用Lambda函数的第二个问题,我将研究使用
Regarding your second question about calling Lambda functions asynchronously without using the SDK, I would look into using API Gateway as a service proxy. This is the recommended way to expose Lambda functions for asynchronous calls.
这篇关于如何异步调用AWS Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!