dimkir / nightmare-lambda-tutorial

Sample project and tutorial to run NightmareJS on AWS Lambda
75 stars 9 forks source link

Getting Error when running on lamda #7

Open mayankTTN opened 6 years ago

mayankTTN commented 6 years ago

I am running the Nightmare locally using Xquartz path on my mac and everything is working fine but when I deploy it on lamda it is throwing error without any error detail just getting blank object in error.

Here is my code:-

nightmarePromise = nightmare
                    .useragent(AGENT_NAME)
                    .goto(params.url)                  
                    .then(function(response){
                        if(!response || !response.code || response.code != 200){
                            const error = {
                                error: true
                                , statusCode: response.code
                                , message: 'An error occured getting dom content.'
                                , detail: response
                                , url: params.url
                            }
                            callback(error, data);
                        }else{
                            return nightmare
                            .wait(7000)
                            .evaluate(function () {
                                return document.documentElement.outerHTML;
                            })
                            .end();
                        }
                    })
                    .catch(function(err){
                        const error = {
                            error: true
                            , statusCode: 400
                            , message: "An error occured getting dom and caught here in the code."
                            , detail: err
                            , url: params.url
                        }
                        callback(error, data);
                    });

On lamda everytime I am thrown into catch blog with {} this as error ,Am I missing something or any misconfiguration I had did for this and mostly it is failing for url styarting with http://

dimkir commented 6 years ago

To make it work on Lambda, you have to make sure you wrap your code inside this "boiler plate" template (as described in the README https://github.com/dimkir/nightmare-lambda-tutorial#write-your-lambda-function-source-code)

Be sure to read Quickstart as there's a significant amount of plumbing to make it transferrable from your local environment to lambda