3

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?

Jithin Sebastian
  • 511
  • 1
  • 6
  • 19
  • btw: you shoud check for err and call callback. function(err, stdout, stderr) { if (err) { callback(err); } else { console.log(stdout); console.log(stderr); callback(); } }); – hellomichibye Dec 01 '16 at 07:29
  • http://stackoverflow.com/questions/34629574/can-bash-script-be-written-inside-a-aws-lambda-function – Paul Dunlop Dec 01 '16 at 08:03

1 Answers1

1

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']
vielmetti
  • 1,864
  • 16
  • 23