question

jesavino avatar image
jesavino asked

Making an HTTPS request in a Lambda Function

Hi all, I've been having some problems with an https request using the lambda function. I'm getting the following error: { "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)" ] } from the following lambda code: 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(); }; Any help would be appreciated!
alexa skills kitsubmission testing certification
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Jamie Grossman avatar image
Jamie Grossman answered
Hi there, Thanks for getting in touch. To my understanding, I can't see anything here. Have you checked out our new examples? They may be a good base to work from. For more information, please see here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/deploying-a-sample-skill-to-aws-lambda#Preparing%20a%20Java%20Sample%20to%20Deploy%20in%20Lambda Regards, Jamie
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.