Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

516
Vistas
How to execute .jar file from AWS Lambda Serverless?

I have tried with following code.

var exec = require('child_process').execFile;
  var runCmd = 'java -jar ' + process.env.LAMBDA_TASK_ROOT + '/src/' + 'myjar.jar'

  exec(runCmd,
    function (err, resp) {
      if (err) {
        cb(null, { err: err})

      } else {
        cb(null, { resp: resp})
      }
    )

Here, I have put my jar file in the root folder and src folder also. but it is giving my following error. I have already added the.jar file with the code.but i got following error.

"err": {
    "code": "ENOENT",
    "errno": "ENOENT",
    "syscall": "spawn java -jar /var/task/src/myjar.jar",
    "path": "java -jar /var/task/src/myjar.jar",
    "spawnargs": [],
    "cmd": "java -jar /var/task/src/myjar.jar"
}

So How, Can I execute this .jar file in AWS Lambda environment? Please help me.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

With Lambda Layers you can now bring in multiple runtimes.

https://github.com/lambci/yumda and https://github.com/mthenw/awesome-layers both have a lot of prebuilt packages that you can use to create a layer so you have a second runtime available in your environment.

For instance, I'm currently working on a project that uses the Ruby 2.5 runtime on top of a custom layer built from lambci/yumbda to provide Java.

    mkdir dependencies
    docker run --rm -v "$PWD"/dependencies:/lambda/opt lambci/yumda:1 yum install -y java-1.8.0-openjdk-devel.x86_64
    cd dependencies
    zip -yr ../javaLayer .
  1. upload javaLayer.zip to aws lambda as a layer
  2. add layer to your function
  3. within your function, java will be located at /opt/lib/jvm/{YOUR_SPECIFIC_JAVA_VERSION}/jre/bin/java
over 4 years ago · Santiago Trujillo Denunciar

0

AWS Lambda lets you select a runtime at the time of creation of that lambda function, or later you can change it again. enter image description here

So, as you are running the Lambda function with NodeJs runtime, the container will not have Java runtime available to it.

You can only have one type of runtime in one container in case of AWS Lambda.

So, Create a separate Lambda with the Jar file that you want to run having Java as the runtime and then you can trigger that lambda function from your current NodeJS lambda function if that's what you ultimately want.

Following is an example of how you can call another Lambda function using NodeJS

var aws = require('aws-sdk');
var lambda = new aws.Lambda({
  region: 'put_your_region_here'
});

lambda.invoke({
  FunctionName: 'lambda_function_name',
  Payload: JSON.stringify(event, null, 2)
}, function(error, data) {
  if (error) {
    context.done('error', error);
  }
  if(data.Payload){
   context.succeed(data.Payload)
  }
});

You can refer to the official documentation for more details.

over 4 years ago · Santiago Trujillo Denunciar

0

In addition to the other answers: Since 2020 December, Lambda supports container images: https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/

Ex.: I created a container image using AWS's open-source base image for python, adding a line to install java. One thing my python code did was execute a .jar file using a sys call.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda