如何异步调用AWS Lambda函数

编程入门 行业动态 更新时间:2024-10-10 15:20:21
本文介绍了如何异步调用AWS Lambda函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人知道异步调用而不是同步调用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.

推荐答案

我正在查看最新的API文档此处,并且似乎仅弃用了AWSLambdaAsyncClient.invokeAsyncAsync(). AWSLambdaAsyncClient.invokeAsync()方法未标记为已弃用.看起来他们只是通过消除对InvokeAsyncRequest和InvokeAsyncResult类以及多余的invokeAsyncAsync()方法的需要来进行代码清理.

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函数的第二个问题,我将研究使用 API网关作为服务代理.建议使用此方法公开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函数

本文发布于:2023-11-28 02:57:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640697.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   AWS   Lambda

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!