0

I have an already existing AWS lambda function whose trigger event is any updates to a particular S3 bucket. I need to run this S3 input through some R scripts. The runtime is node.js and other events depend on this being a node.js configuration. The scripts I need to run must be in R because other languages aren't suitable.

How to I get the R scripts to run from this node.js lambda function?

  • Event type: All object create events
  • Runtime: Node.js 14.x
King_Cordelia
  • 223
  • 1
  • 7
  • 1
    You probably need to build a custom container to run on Lambda instead of trying to use the NodeJS runtime. https://aws.amazon.com/about-aws/whats-new/2020/12/aws-lambda-now-supports-container-images-as-a-packaging-format/ – Mark B Oct 14 '21 at 20:25

1 Answers1

1

If you want to try and run two languages in the same lambda your only choice is to deploy a custom Docker image for the lambda container with both the languages installed.

However. Its not like there is a command line for you to access, so unless you code your nodejs lambda to call the R script and wait for its response(which is technically possible) you wont be able to just call it.

You are probably better off deploying a second lambda with a custom docker that just has R on it (as R is not a language lambda supports yet) and call that lambda using the SDK and wait for its response.

Though, there is this article that indicates there is a lambda layer that may give you R access - you should check that out

lynkfox
  • 2,003
  • 1
  • 8
  • 16
  • Thanks. Can a docker image for the lambda container use the same trigger as another lambda function? The node.js lambda requires the same s3 trigger that I need for my lambda. – King_Cordelia Oct 15 '21 at 14:04
  • 1
    A docker image doesn't use any trigger in Lambda. When you select a docker image for Lambda deployment it uses that as the backend for the Lambda. Everything else is handled through the AWS Api's between services - including s3 file triggers. You can trigger as many lambdas off the same trigger as you want as long as they are all listening to it. – lynkfox Oct 15 '21 at 15:38
  • Oh ok, cool. So, essentially, the docker image lets you get around the AWS lambda trigger limit, i.e., only one lambda function per trigger event. Am I understanding that right? – King_Cordelia Oct 18 '21 at 15:04
  • 1
    no, not at all. That is not what that does. You still only get one lambda trigger per invoke - thats how Lambdas scale. They are not servers, they are single individual functions that can be called multiple times simultaneously. The docker image is required in order to have both languages available - standard images for lambda only have one language installed per image. The rest, would be using node js code to call the R script and run it, inside the lambda handler. – lynkfox Oct 18 '21 at 15:36
  • Oh ok, thank you. How can you use node js code to call R code? I haven't seen any examples of that. I found this stackoverflow discussion. https://stackoverflow.com/questions/23450534/how-to-call-a-python-function-from-node-js – King_Cordelia Oct 19 '21 at 13:07