后续 Lambda 调用之间的数据共享

huangapple go评论51阅读模式
英文:

Data sharing between subsequent lambda's invocation

问题

我有一个接受值数组作为输入的Lambda函数。该Lambda的任务是下载一些数据并将数组中的每个项目与下载的数据进行比较。比较是通过使用相同的Lambda来执行,传递数组中的项目进行的。

我的问题是,我能否在这些调用之间共享数据?因为我要比较的数据大约有1/2 Mb。我不想反复下载相同的数据。

如果没有办法这样做,您能否提供一些解决这个问题的建议?

我已经查看了/tmp文件,但没有人能保证后续的调用会从同一个容器中提供服务。如果它们不是从同一个容器提供服务,它们无法共享/tmp文件。

英文:

I have a lambda that gets as input array of values. The lambda's task is to download some data and compare each item in the array with the downloaded data. The comparison is performed by invoking the same lambda with the item in the array.

My question is, can i share data between the invocations? Because the data that i compare it with is weighting about 1/2 Mb's. I dont want to download the same data over over?

If there isn't a way to do so, can you pls advice about ways to approach this problem?

i have looked the /tmp file but no one guarantee that the subsequent invocation would be served from same container. and if they arent served from the same container, they cant share the /tmp file.

答案1

得分: 4

你是正确的,Lambda函数的后续调用可能不会来自相同的容器,因此,你不能依赖通过/tmp目录在调用之间共享数据。每次Lambda函数的调用都是无状态的,并且与先前的调用隔离。

为了解决这个问题,你可以将数据存储在外部位置,比如EFS、S3或任何其他存储(Lambda层也可能是一个不错的选择)。

英文:

You are correct that subsequent invocations of a Lambda function may not be served from the same container, and therefore, you cannot rely on sharing data via the /tmp directory between invocations. Each invocation of a Lambda function is stateless and isolated from previous invocations.

To address the Issue, you can store the data somewhere external, like EFS, S3 or any other store (Lambda layer might also be a good option)

答案2

得分: 1

如果要获取的数据永远不会更改,那么在编译JS时获取它,并将其放入Lambda的部署包中。

英文:

If the data to be fetched never changes, then fetch it when you compile the JS and put it into the lambda's deployment packaged.

答案3

得分: 0

你可以检查Lambda缓存。你可以在一个容器的范围内缓存一些数据,以便在调用之间使用。

英文:

You can check Lambda caching. You are able to cache some data between invocations in scope of one container.

huangapple
  • 本文由 发表于 2023年7月27日 20:54:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76779953.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定