javaamazon-web-servicesaws-lambdaaws-sdkaws-sdk-java-2.0

AWS Lambda JavaCompiler instance


In an AWS Lambda Java 8 Function, is it possible to get an instance of SystemJavaCompiler? Here's a snippet:

final File root = new File("/tmp");    
final File sourceFile = new File(root, type.getSourceFilename());

sourceFile.getParentFile().mkdirs();

Files.write(sourceFile.toPath(), templateString.getBytes(StandardCharsets.UTF_8));

final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
compiler.run(null, null, null, sourceFile.getPath());

I'm attempting to dynamically compile source code in a Lambda and ToolProvider.getSystemJavaCompiler() throws a NullPointerException. This works great locally. I was hoping to avoid deploying an EC2 instance to benefit from the resource savings of Lambda.


Solution

  • Maybe there is no SDK, JRE only.