bakdata / aws-lambda-r-runtime

Serverless execution of R code on AWS Lambda
https://medium.com/bakdata/running-r-on-aws-lambda-9d40643551a6
MIT License
144 stars 53 forks source link

Workspace cleared between invocations #50

Closed johan13 closed 4 years ago

johan13 commented 4 years ago

Most AWS lambda runtimes keep global variables around between invocations. The R runtime seems to clear it with rm(list = ls()) and then source the code again after each invocation. This means we cannot cache data between calls and cannot keep database connections open. Is there any reason why the R runtime was implemented this way?

philipp94831 commented 4 years ago

We did that because different Lambdas using the same runtime could be launched in the same lambda container and we want to avoid side effects. Furthermore, this should also increase security because we want to avoid that objects from one invocation are shared with a different invocation

johan13 commented 4 years ago

Thank you for the quick reply! My understanding was that each lambda function gets its own container. I understand the security-argument, but it is a little inconsistent compared to the AWS-provided runtimes.

I will try building the layer with and without clearing the environment and see which one we end up using. Until #49 is resolved, I guess I cannot use the pre-built layer anyway.