Monday 8 May 2017


Dealing with Amazon Service Simulator Errors

When developing Alexa skills, a message I frequently get on the Amazon Developer Console in the service simulator is:
"The remote endpoint could not be called, or the response it returned was invalid."
There are many causes for this, some of which are far from obvious.

1. The skill cannot be contacted.


Check the Service Endpoint Type and Endpoint in the Configuration in the Amazon Developer Console correctly point to a skill (either on a https server, or on, for example, the EU Amazon AWS Server).

2. The request is incorrectly formatted - invalid card

In the json response, if you follow the developer examples, you can have an entry

{
   "version": "1.0",
   "response": {
      "card": {},
      .....
This works fine when running on the AWS Server, but fails with the dreaded 'endpoint' error.  If you don't have anything useful to put in the "card", don't add the entry at all to the response.

3. The request is incorrectly formatted - invalid session

I captured the real output of an echo (see next section), and submitted it as a JSON input in the Service Simulator.  I had to manually add in the "attributes" line to make the simulator work correctly.  This code did, however, work in the AWS Lambda test environment.

"session": {
    "sessionId": "SessionId.blah",
    "application": { "applicationId": "amzn1.ask.skill.blah" },
    "attributes": {},
     "user": { "userId": "amzn1.ask.account.blah" },
     "new": true
 },

4. Check your Spelling

The spelling of the code is in American, not English.  Note that the AudioPlayer.Play is Behavior, not Behaviour!
"playBehavior": "REPLACE_ALL",

Things To Try

Copy and Paste from the Simulator

Use the service simulator in the developer console, then copy the JSON request, and paste it into the 'Actions / Configure Test Event' on the Lambda server.  This way, you may see the cause of the error.

Copy and Paste from a Real Echo

Modify your code to include the following line (or equivalent) in your javascript:
exports.handler = (event, context, callback) => {
   console.log("Request: %j", event) ;
   .....
Ask your Echo to launch the skill (using whatever utterance you need to test the appropriate function).  Now, launch the CloudWatch (link to EU Server), and look at the latest log entry.  You can then see the actual request from the Echo.

You can paste this request into the 'Actions / Configure Test Event' on the Lambda server, or into the JSON input in the Amazon Developer simulator.

You will notice that the Simulator and the Echo sometimes give differently formatted requests!
And the Simulator and AWS Lambda server give different responses (or errors!)



No comments:

Post a Comment