I am working on a function based on ytdl module for node.js. Actually, i just want to downloqd a youtube video. When I test my function, I got this error :
2017-12-16T17:25:48.627Z 27dbca8d-e286-11e7-9f17-851e6c66e221 Error: spawn EACCES
at exports._errnoException (util.js:1018:11)
at ChildProcess.spawn (internal/child_process.js:319:11)
at exports.spawn (child_process.js:378:9)
at exports.execFile (child_process.js:143:15)
at call (/var/task/node_modules/youtube-dl/lib/youtube-dl.js:163:5)
at Function.getInfo (/var/task/node_modules/youtube-dl/lib/youtube-dl.js:285:5)
at module.exports (/var/task/node_modules/youtube-dl/lib/youtube-dl.js:107:10)
at exports.handler (/var/task/index.js:6:14)
after some googling requests, I found that it is related to access problem. However, my code have no special operations that needs access permission. Could you help please
var path = require('path');
var fs = require('fs');
var ytdl = require('./node_modules/youtube-dl');
exports.handler = (event, context, callback) => {
var video = ytdl('https://www.youtube.com/watch?v=AW8OOp2undg',
// Optional arguments passed to youtube-dl.
['-o', '/tmp/test.mp4']);
var size = 0;
video.on('info', function(info) {
'use strict';
size = info.size;
console.log('Got video info');
var file = path.join(__dirname, info._filename);
video.pipe(fs.createWriteStream(file));
});
var pos = 0;
video.on('data', function data(chunk) {
'use strict';
pos += chunk.length;
// `size` should not be 0 here.
if (size) {
var percent = (pos / size * 100).toFixed(2);
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
process.stdout.write(percent + '%');
}
});
video.on('end', function end() {
'use strict';
console.log('\nDone');
});
callback(null, 'Hello from Lambda');
};
/tmp/. Also: You don't have to writerequire('./node_modules/youtube-dl'). Justrequire('youtube-dl')is enough since it will search in thenode_modulesfolder first anyway.sudo chmod -R a+rwx /tmp/- however keep in mind, this will make the folder read and writable for anyone. Let me know if that worked. I add it as an answer then.