0

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.

Amit Hajaj
  • 68
  • 7
  • 1
    No, there is no way to share any data within the Lambda. The data needs to either be in the invocation payload or stored externally and loaded, e.g. in / from S3 or DynamoDB. – luk2302 Jul 27 '23 at 12:59

3 Answers3

4

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)

Zoro
  • 127
  • 8
1

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.

Tobin
  • 1,698
  • 15
  • 24
0

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

Kamil
  • 17
  • 1
  • how can i check or verify that the lambda's i trigger subsequently are in scope of the same container? – Amit Hajaj Jul 27 '23 at 13:13
  • How to [detect warm/cold starts](https://stackoverflow.com/questions/47061146/aws-lambda-identifying-cold-starts). That said, a solution cannot rely on warm start. It should always have a fallback for the cold start scenario. – jarmod Jul 27 '23 at 14:05
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 05 '23 at 08:57