Can bash script be written inside a AWS Lambda function

Hardik Kamdar picture Hardik Kamdar · Jan 6, 2016 · Viewed 48.7k times · Source

Can I write a bash script inside a Lambda function? I read in the aws docs that it can execute code written in Python, NodeJS and Java 8.

It is mentioned in some documents that it might be possible to use Bash but there is no concrete evidence supporting it or any example

Answer

Daniel Cortés picture Daniel Cortés · Jul 12, 2016

Something that might help, I'm using Node to call the bash script. I uploaded the script and the nodejs file in a zip to lambda, using the following code as the handler.

exports.myHandler = function(event, context, callback) {
  const execFile = require('child_process').execFile;
  execFile('./test.sh', (error, stdout, stderr) => {
    if (error) {
      callback(error);
    }
    callback(null, stdout);
  });
}

You can use the callback to return the data you need.