简体   繁体   English

如何同时调用相同的AWS Lambda function?

[英]How to call same AWS Lambda function concurrently?

I have a AWS lambda function which process data and returns calculated results, then results saved to the db by java backend.我有一个 AWS lambda function 处理数据并返回计算结果,然后由 java 后端将结果保存到数据库中。 Each call takes approximately 2-3 seconds.每次通话大约需要 2-3 秒。 I followed this tutorial and successfully invoked lambda function from java.我按照本教程成功地从 java 调用了 lambda function。 But my payload is big and I want to split it and call same function multiple times.但是我的有效载荷很大,我想拆分它并多次调用相同的 function。 One way of doing it is using many threads.一种方法是使用多个线程。 My question is, is there any better way of doing this?我的问题是,有没有更好的方法来做到这一点? Does aws lambda library has support for it? aws lambda 库是否支持它?

Example payload:有效载荷示例:

{
user_1: data_1,
user_2: data_2,
...
user_300: data_300
}

I simply want to call lambda function for each user and finish processing of all users data less than 5 seconds.我只想为每个用户调用 lambda function 并在 5 秒内完成所有用户数据的处理。

UPDATE: One way is using Asynchronous Programming as stated in the documentation.更新:一种方法是使用文档中所述的异步编程 Another way can be adding an API Gateway and doing async post request.另一种方法是添加 API 网关并执行异步发布请求。

To me, Lambda should be as lightweight as possible.对我来说,Lambda 应该尽可能轻巧。 Doing 4MB of payload, looks like you need a different approach.做 4MB 的有效载荷,看起来你需要一种不同的方法。

S3 bucket will do, but I prefer API gateway with something like How do you create an asynchronous HTTP request in JAVA? S3 存储桶可以,但我更喜欢 API 网关,例如如何在 JAVA 中创建异步 HTTP 请求? , using multiple threads on the producer of that information. ,在该信息的生产者上使用多个线程。

Yes, definitely, I would go for the API gateway approach in which you can still use for smaller payloads as well.是的,当然,我会为 API 网关方法使用 go,在这种方法中您仍然可以用于较小的有效负载。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM