Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run bash script from node AWS Lambda function

I have a node lambda function from which i'am running a bash script.

'use strict';

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

exports.handler = (event, context, callback) => {
    const message = event.message;
    const child = exec('./bs.sh ' + message, function(err, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    });
};

When i run this, i get /bin/sh: ./bs.sh: Permission denied . I tried changing permissions with chmod 777 bs.sh before zipping the function, but that too didn't work. Is it a limitation of lambda or an error in my approach?

like image 916
Jithin Sebastian Avatar asked Apr 12 '26 19:04

Jithin Sebastian


1 Answers

You'll want to look at

https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/

In particular this bit:

Including your own executables is easy; just package them in the ZIP file you upload, and then reference them (including the relative path within the ZIP file you created) when you call them from Node.js or from other processes that you’ve previously started. Ensure that you include the following at the start of your function code:

process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']

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!