question

sandeep0803 avatar image
sandeep0803 asked

Call to External Services Recording response

hey, I am working with Lambda to create a Alexa app in which i need to call some external services and get their response for the user. any idea how to do that? also is there any way to call services internal to Amazon(not AWS) from lambda. It would really help.
alexa skills kitdebugging
10 |5000

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

sandeep0803 avatar image
sandeep0803 answered
Also if can i access internal http (amazon network) end point from lambda? it will help me a lot.
10 |5000

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

James Chivers avatar image
James Chivers answered
I've zero experience with Lambda, but a quick search reveals: http://stackoverflow.com/questions/27521169/can-aws-lamdba-speak-to-external-internet-services/27932216 I'm assuming if it's vanilla JavaScript / Node - then, yes, you probably could (should!) be able to make an external call. Looks like there's a 60 second timeout on them.
10 |5000

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

James Chivers avatar image
James Chivers answered
...and for your second question, then I would assume so too - providing the endpoint is Internet accessible, or, you invoke whatever credentials are necessary (via the request call from your JavaScript) to authenticate. HTH, James
10 |5000

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

Greg Crawford avatar image
Greg Crawford answered
It is definitely possible to call external services from Lambda. The following is a sample using the 'https' module - you could use http if your external resource doesn't use SSL. Make sure that you don't call 'context.done' until all callbacks have completed. // Some sample code on how to make an external call from Lambda. // Make sure to set the host and path according to service you are calling exports.handler = function(event, context) { console.log('Lambda Handler start...'); getToken(function(status) { context.done(null, status); }); }; function getToken(callback) { var http = require('https'); var options = { host: ' example.com', port: 443, path: '/token', headers: {}, method: 'GET' }; var req = http.request(options, function(res){ res.setEncoding('utf-8'); var responseString = ''; res.on('data', function(data) { responseString += data; }); res.on('end', function() { var json = JSON.parse(responseString); callback('OK'); }); }); req.write(""); // Value written will depend on external resource req.end(); }
10 |5000

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

Ross@Amazon avatar image
Ross@Amazon answered
Alexa Skills Kit samples can be found here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/using-the-alexa-skills-kit-samples-node. By following the included instructions you should be able to build these sample skills very quickly and easily. These examples will help you to better understand how Alexa skills should be created. The samples Tide Pooler and History Buff are good examples of how to call an external service.
10 |5000

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