2015-09-03 25 views
0

我一直在使用lambda函数对https请求进行一些处理。我收到以下错误:Amazon Echo开发中的套接字挂起错误

{ 
    "errorMessage": "socket hang up", 
    "errorType": "Error", 
    "stackTrace": [ 
    "SecurePair.error (tls.js:1011:23)", 
    "EncryptedStream.CryptoStream._done (tls.js:703:22)", 
    "CleartextStream.read [as _read] (tls.js:499:24)", 
    "CleartextStream.Readable.read (_stream_readable.js:341:10)", 
    "EncryptedStream.onCryptoStreamFinish (tls.js:304:47)", 
    "EncryptedStream.g (events.js:180:16)", 
    "EncryptedStream.emit (events.js:117:20)", 
    "finishMaybe (_stream_writable.js:360:12)", 
    "endWritable (_stream_writable.js:367:3)", 
    "EncryptedStream.Writable.end (_stream_writable.js:345:5)" 
] 
} 

从下面的代码。此代码是在Amazon的AWS Lambda服务中的Nodejs中编写的。

var https = require('https'); 
var options = { 
    host: 'host.dynamic.com', // global IP goes here. I've tried a DDNS host and the address of my server 
    port: 8080, 
    method: 'POST', 
    headers: { 
     'Content-Type': 'text' 
    } 
}; 
var data = 'OFF'; 

/** 
* Pass the data to send as `event.data`, and the request options as 
* `event.options`. For more information see the HTTPS module documentation 
* at https://nodejs.org/api/https.html. 
* 
* Will succeed with the response body. 
*/ 
exports.handler = function(event, context) { 
    var req = https.request(options, function(res) { 
    var body = ''; 
    console.log('Status:', res.statusCode); 
    console.log('Headers:', JSON.stringify(res.headers)); 
    res.setEncoding('utf8'); 
    res.on('data', function(chunk) { 
     body += chunk; 
    }); 
    res.on('end', function() { 
    console.log('Successfully processed HTTPS response'); 
    // If we know it's JSON, parse it 
    if (res.headers['content-type'] === 'application/json') { 
     body = JSON.parse(body); 
    } 
    context.succeed(body); 
}); 
}); 
console.log("Before the error"); 
req.on('error', context.fail); 
req.write(data); 
console.log("Before req.end()"); 
req.end(); 
}; 

任何帮助,将不胜感激

+0

我也看到了SO帖子有同样的错误,但由于我在AWS Lambda上托管了这个,所以除了这里编写的代码之外,我没有太多的控制权。 – Jesavino

回答

0

我发现这个问题。我与之通信的nodejs服务器需要'http'而不是'https'。