jsii icon indicating copy to clipboard operation
jsii copied to clipboard

Inability to execute JSII Runtime in AWS Lambda with Java runtime due to Nodejs child process dependency

Open lukepopp opened this issue 6 years ago • 4 comments

:rocket: Feature Request

Affected Languages

  • [ ] TypeScript or Javascript
  • [ ] Python
  • [X] Java
  • [ ] .NET (C#, F#, ...)

General Information

  • JSII Version: 1.13.0

  • Platform: Ubuntu 20.04

  • [ ] I may be able to implement this feature request

  • [ ] This feature might incur a breaking change

Description

The JsiiRuntime class in jsii-runtime-1.13.0.jar contains code which creates a ProcessBuilder which is hardcoded to execute nodejs

ProcessBuilder pb = new ProcessBuilder("node", jsiiRuntimeExecutable);

This means that no other software can be used to to start the process to run the extracted JS file. Furthermore, as mentioned in the title, the reliance on nodejs to execute the js file means that the JSII runtime can't be executed inside an AWS Lambda function using the Java runtime.

Proposed Solution

There are JARs available that can be used to execute js files and ProcessBuilder can execute jar files inside the Lambda Java runtime. Is it possible to test running the js file using one of these frameworks and incorporate it into the jsii runtime? I personally tried Trireme but it couldn't successfully execute the extracted js. It would be great to have a solution in place to support a pure JVM environment. Furthermore, the executable name should be able to be configured using a env variable as opposed to being hardcoded "node".

lukepopp avatar Oct 15 '20 04:10 lukepopp

Our runtime components are not just dependent on running JavaScript, they actually also depend on the node standard library. Additionally, our previous experience in using in-JVM javascript runners had shown that the performance of those engines was largely inadequate for the purpose... Synthesizing a fairly modest CDK Application back in the days using this method required several seconds... Complex apps with non-trivial construct trees would get to run unbearably slowly.

Right now, should you need to replace node with another runtime (albeit knowing that node is the only one we have tested against and officially support), you could add a script named node ahead of your PATH that forwards to your runtime of choice. This is admittedly not very pretty, but it would work. I think your suggestion to make this environment-customizable is actually a pretty good idea!

Finally - we have been trying to come up with ways to simplify the setup experience for users, trying to not require they manually install a compatible node runtime if they do not have one just yet... And are constantly reviewing ways we could run 100% embedded (possibly in-process). This is easier said than done, but is where we'd want to land in the long run. I was not aware of Trireme, but reading the README.md on their page, it seems to only support ancient versions of node (0.10.32 and 0.12.7 are what's mentioned), which is inadequate for jsii, unfortunately.

RomainMuller avatar Oct 19 '20 08:10 RomainMuller

Thanks @RomainMuller, I'm assuming that there is not going to be a pure JVM solution for a while (if ever) to allow execution in a Java Lambda (non custom runtime). I appreciate there was no intention to execute inside a Lambda but I was thinking that building APIs around libs that include JSSII could open up some interesting possibilities.

lukepopp avatar Oct 20 '20 01:10 lukepopp

You're correct that ti'll take a while before we can remove the need fro an "external" node runtime.

Since you're running in Lambda -- have you considered bringing in a node layer?

RomainMuller avatar Dec 14 '20 13:12 RomainMuller

This issue has not received any attention in 2 years. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Jun 25 '23 06:06 github-actions[bot]