0
votes

I am invoking aws lambda function from aws console and I am getting an error, Please help me my code is blowing

const ffmpeg = spawn('ffmpeg', ["-framerate", "0.5", "-i", myarray[0], "-i", 
    myarray[1], "-i", myarray[2], "-pix_fmt", "yuv420p", '-codec:v', 'libx264', 
   "/var/task/bin/video.mp4"]);


Error: spawn EACCES
   at _errnoException (util.js:1022:11)
   at ChildProcess.spawn (internal/child_process.js:323:11)
   at exports.spawn (child_process.js:502:9)
   at Timeout.setTimeout [as _onTimeout] (/var/task/handler.js:23:22)
   at ontimeout (timers.js:482:11)
   at tryOnTimeout (timers.js:317:5)
   at Timer.listOnTimeout (timers.js:277:5)

My Code

var AWS = require("aws-sdk");
var s3 = new AWS.S3();
const spawn = require('child_process').spawn;


var myarray = [];
//module.exports.hello
exports.handler = function (event, context, callback) {

return new Promise(function (resolve, reject) {

process.env.PATH = require("path").join(__dirname, "bin") + ":" + process.env['LAMBDA_TASK_ROOT'] +'; chmod 755 /tmp/bin/ffmpeg';

console.log(process.env.PATH);

GetImagesFromS3();

setTimeout(() => {
  const ffmpeg = spawn('ffmpeg', ["-framerate", "0.5", "-i", myarray[0], "-i", myarray[1], "-i", myarray[2], "-pix_fmt", "yuv420p", '-codec:v', 'libx264', '/temp/video.mp4']);
  ffmpeg.stderr.on('data', (data) => {
    console.log(`${data}`);
  });
  ffmpeg.on('close', (code) => {
    console.log('close', code)
  });
  ffmpeg.on('error', (code) => {
    console.log('error', code)
  });
}, 5000);
});
};


// get images from s3 bucket
function GetImagesFromS3() {
return new Promise(function (resolve, reject) {
var params = {
  Bucket: 'hhotimages'
};
s3.listObjects(params, function (err, data) {
  var bucketContents = data.Contents;
  for (var i = 0; i < bucketContents.length; i++) {
    var urlParams = {
      Bucket: 'hhotimages',
      Key: bucketContents[i].Key
    };
    s3.getSignedUrl('getObject', urlParams, function (err, url) {
      console.log('the url of the image is', url);
      myarray.push(url);
    });
    }

  });
  });
 }
1
is it working ok when you test it from the console?Akber Iqbal
nothing working getting same errorPramod Gehlot
can you share the complete function? or part of it which replicates the issue... get your function to run successfully through the tests in the console before invoking it from other places.Akber Iqbal
@AIqbalRaj i have added my code please help mePramod Gehlot

1 Answers

0
votes

It looks like you're already shipping ffmpeg with your lambda function or else you would be getting ENOENT.

However, the ffmpeg you've packaged needs the executable bit set (chmod +x ffmpeg prior to packaging). Without this you do not have permission to execute ffmpeg, which is probably why you're getting EACCES.

You might also get this if your ffmpeg was compiled for something other than the lambda environment.