8

I've created a simple Lambda function to call a webpage, this works fine when I test it from the functions page however when trying to create a skill to call this function I end up with a "The remote endpoint could not be called, or the response it returned was invalid." error.

Lambda Function

var http = require('http');

exports.handler = function(event, context) {
  console.log('start request to ' + event.url)
  http.get(event.url, function(res) {
    console.log("Got response: " + res.statusCode);
    context.succeed();
  }).on('error', function(e) {
    console.log("Got error: " + e.message);
    context.done(null, 'FAILURE');
  });

  console.log('end request to ' + event.url);
}

The Test Event code looks like this:

{
  "url": "http://mywebsite.co.uk"
}

and I've added a trigger for the "Alexa Skills Kit".

The ARN for this function is showing as:

arn:aws:lambda:us-east-1:052516835015:function:CustomFunction

Alexa Skill (Developer Portal)

I've then created a skill with a simple Intent:

{
 "intents": [
   {
 "intent": "CustomFunction"
   }
 ]
}

and created an Utterance as:

CustomFunction execute my custom function

In the Configuration section for my skill I have selected the "AWS Lambda ARN (Amazon Resource Name)" option and entered the ARN into the box for North America.

In the Test -> Service Simulator section, I've added "execute my custom function" as the Text and this changes the Lambda Request to show:

{
  "session": {
"sessionId": "SessionId.a3e8aee0-acae-4de5-85df-XXXXXXXXX",
"application": {
  "applicationId": "amzn1.ask.skill.XXXXXXXXX"
},
"attributes": {},
"user": {
  "userId": "amzn1.ask.account.XXXXXXXXX"
},
"new": true
  },
  "request": {
"type": "IntentRequest",
"requestId": "EdwRequestId.445267bd-2b4a-45ef-8566-XXXXXXXXX",
"locale": "en-GB",
"timestamp": "2016-11-27T22:54:07Z",
"intent": {
  "name": "RunWOL",
  "slots": {}
}
  },
  "version": "1.0"
}

but when I run the test I get the following error:

The remote endpoint could not be called, or the response it returned was invalid.

Does anyone have any ideas on why the skill can't connect to the function?

Thanks

Jedi
  • 3,088
  • 2
  • 28
  • 47
ca8msm
  • 1,170
  • 3
  • 15
  • 37

3 Answers3

4

The Service Simulator built into the Amazon Alexa Developer Console has known issues. Try copying the JSON generated by the Simulator and pasting it into your lambda function's test event. To access lambda's test events first find the blue 'Test' button. Next to that button select the (Actions Drop down menu) -> (Configure Test Event) -> Paste the provided JSON into the code area -> (Save and Test). Lambda's built in testing features are much more reliable than Alexa's.

If this does not solve the problem lambda's testing event returns a complete stackTrace and error codes. It becomes much easier to trouble shoot when every error isn't "The remote endpoint could not be called, or the response it returned was invalid."

{
  "session": {
"sessionId": "SessionId.a3e8aee0-acae-4de5-85df-XXXXXXXXX",
"application": {
  "applicationId": "amzn1.ask.skill.XXXXXXXXX"
},
"attributes": {},
"user": {
  "userId": "amzn1.ask.account.XXXXXXXXX"
},
"new": true
  },
  "request": {
"type": "IntentRequest",
"requestId": "EdwRequestId.445267bd-2b4a-45ef-8566-XXXXXXXXX",
"locale": "en-GB",
"timestamp": "2016-11-27T22:54:07Z",
"intent": {
  "name": "RunWOL",
  "slots": {}
}
  },
  "version": "1.0"
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Caleb Gates
  • 914
  • 7
  • 20
  • This works for me. Or you can keep on trying until you succeed!. – Shamnad P S Aug 17 '17 at 06:03
  • 1
    Skill Page -> Test -> Service Simulator -> Text tab -> Entered Utterance and hit "Ask Skill Name" button and in "Service Request" textarea it generated the request containing my linked account access token. However in "Service Response" I got "The remote endpoint could not be called, or the response it returned was invalid.". Then I copied the JSON from "Service Request" and switched to JSON tab and paste the copied JSON in "Json Request" textarea and hit "Ask Skill Name" and I got the expected JSON in "Service Response". That is strange but it is acceptable for me right now. – Jignesh Gohel Aug 24 '17 at 12:44
3

​While uploading .zip, do not compress the folder into .zip.

Instead, go into the folder, select package.json, index.js and node modules & then compress them and then upload the .zip.

markwalker_
  • 12,078
  • 7
  • 62
  • 99
Arshima
  • 31
  • 1
0

This error message is very broad and may imply a lot of different issues. I was getting this error and in my case it was a timeout issue. How long does that website you are pinging taking to respond? The timeout doesn't seem to be properly documented, see my original question here: Troubleshooting Amazon's Alexa Skill Kit (ASK) Lambda interaction

Community
  • 1
  • 1
Josep Valls
  • 5,483
  • 2
  • 33
  • 67