0

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');

};
7
  • Check if you have set correct permissions for the folder /tmp/. Also: You don't have to write require('./node_modules/youtube-dl'). Justrequire('youtube-dl') is enough since it will search in the node_modules folder first anyway. Commented Dec 19, 2017 at 14:31
  • Thank you. Could you give a permission sample fot /tmp. Commented Dec 19, 2017 at 14:54
  • 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. Commented Dec 19, 2017 at 14:59
  • I have never executed a command on aws lambda. In fact i am a newbie. Commented Dec 19, 2017 at 15:00
  • Do you have ssh access to the server? I never used aws lambda. Commented Dec 19, 2017 at 15:02

2 Answers 2

1

node-ytdl use precompiled binaries so you should deploy your lambda from the same OS/arch as the target.

Or use the pure javascript module :

If you're only interested in downloading only from youtube, you should consider using pure Javascript youtube downloading module. => https://github.com/fent/node-ytdl

source : https://www.npmjs.com/package/youtube-dl

Sign up to request clarification or add additional context in comments.

Comments

0

just change permission of youtube-dl:

chmod +x youtube-dl

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.