Alexa Skill ARN - The remote endpoint could not be called, or the response it returned was invalid

ca8msm picture ca8msm · Nov 28, 2016 · Viewed 7.6k times · Source

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

Answer

Caleb Gates picture Caleb Gates · Aug 3, 2017

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"
}