Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

node.js - AWS nodejs lambda function, change dynamically the value of environment variable

I am running a lambda function on AWS that takes a very long time to execute (big data). It is exceeding the maximum 900 seconds (15 minutes) allowed in lambda, so the function is timing out.

Using context.getRemainingTimeInMillis(), I am thinking to trigger a new instance of the lambda just before getting the timeout. However, looks like there is no way to stop the execution of a lambda, once it is started, meaning that if I make any mistake, we could enter in a infinite loop and lambda would be running forever?? Anyway, to avoid this, I am thinking to set a environment variable called "stopExecution", which defaults to false, but in case for some reason I need to stop the execution, set it up to true.

Basically in my nodejs code I read the variable process.env.stopExecution. Now, my question is, the environment variables in a lambda, are dynamic? If I change the value during the execution, the lambda will read the new value and therefore stop? Or the environment variables are only read at the launch time of the function, and they keep the same value during the execution, so the only way to read the new value is to wait for them to stop and launch them again?

Also, if some faced the same issue as myself and wants to propose a better solution, feel free.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To answer the question, though, there are many ways to have Lambdas more dynamic in nature by storing state in a DynamoDB, S3, Parameter store and have the state refreshed. However, I would not use it to solve your problem. I have personally been there before, and things do start getting complex. I would either try to perform a more map-reduce type approach (also complex, sometimes) or use an EC2 (KISS approach) that terminates after running.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...