AWS Lambda:错误:getaddrinfo ENOTFOUND [英] AWS Lambda: Error: getaddrinfo ENOTFOUND

查看:589
本文介绍了AWS Lambda:错误:getaddrinfo ENOTFOUND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是AWS Lambda函数中的代码:

here's the code in AWS Lambda function:

var https = require('https');
exports.handler = (event, context, callback) => {
    var params = {
        host: "bittrex.com",
        path: "/api/v1.1/public/getmarketsummaries"
    };
    var req = https.request(params, function(res) {
        var test = res.toString();
        console.log(JSON.parse(test));
        //console.log(JSON.parse(res.toString()));
    });
    req.end();
};




错误:getaddrinfo ENOTFOUND https://bittrex.com
https:/ /bittrex.com:443
在errnoException(dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete](dns.js:76:26)

Error: getaddrinfo ENOTFOUND https://bittrex.com https://bittrex.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

我无法想象,请帮忙。其他解决方案无效。

I am not able to figure, please help. Other solutions did not work.

推荐答案

我修改了您的代码,以便在AWS Lambda Node.js 6.10中正常工作。我将Lambda超时设置为60秒进行测试。

I modified your code to work correctly in AWS Lambda Node.js 6.10. I set the Lambda timeout to be 60 seconds for testing.

最大的变化是添加res.on('data',function(chunk){}:和res.on('end',function(){}。

The big change is adding "res.on('data', function(chunk) {}:" and "res.on('end', function() {}".

var https = require('https');
exports.handler = (event, context, callback) => {
    var params = {
        host: "bittrex.com",
        path: "/api/v1.1/public/getmarketsummaries"
    };
    var req = https.request(params, function(res) {
        let data = '';
        console.log('STATUS: ' + res.statusCode);
        res.setEncoding('utf8');
        res.on('data', function(chunk) {
            data += chunk;
        });
        res.on('end', function() {
            console.log("DONE");
            console.log(JSON.parse(data));
        });
    });
    req.end();
};

这篇关于AWS Lambda:错误:getaddrinfo ENOTFOUND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆