Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

515
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda