Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke shell script in AWS Lambda using node.js

I am new to AWS Lambda. I am trying to invoke a basic "Hello World" shell script from an AWS Lambda function coded in node.js.

run.js file contains the following:


#!/bin/bash
echo "Hello, World!"  

I have also coded the function by storign it in an index.js file containing the following:


var exec = require('child_process').exec;

exports.handler = function(event, context) {
    exec('./run.sh' , function(error, stdout) {
        context.done(error, stdout);
    });
};

I have created a zip file containing both files and have uploaded it to AWS Lambda console by creating a new Lambda function and granting it a lambda_basic_execution role.

I was expecting to be able to see the Hello World, have tried variations of this code but so far have been unable to call a shell script from an AWS Lambda function.

Thanks in advance!

Andy

like image 577
Rlearner Avatar asked Jun 17 '26 12:06

Rlearner


1 Answers

Lambda only supports child_process.spawn and child_process.spawnSync. Try changing your call to child_process.exec and that should fix it for you.

like image 135
Chris Franklin Avatar answered Jun 20 '26 07:06

Chris Franklin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!