Does AWMS lambda store global variables?

I created a simple increment counter, as shown below.

global.counter = 0;
exports.handler = (event, context, callback) => {
    // TODO implement
    callback(null, ++global.counter);
};

Whenever I test this function, I get an extra value as expected.

Is this the right approach or do I need to store the counter in a cloud database?

+4
source share
2 answers

When you call your lambda function for the first time, the container loads in the background using AWS.

When you call your lambda function several times, you MAY get the same container to optimize the startup time and installation delay.

You cannot rely on this behavior, but you must know that it exists.

vars, Lambda, - - ( ).

,

+9

, AWS Elasticache (Memcached) (, ). , ( python ) .

, , , "".

+1

Source: https://habr.com/ru/post/1675127/


All Articles