If you have tried building an Alexa Skill, you might have gotten the error “The remote endpoint could not be called, or the response it returned was invalid.”
For me, the error was related to uploading a zip file with the index.js and its node_modules libraries to the Lambda service. No matter what zip file I would upload, I’d get the following error:
"errorMessage": "Cannot find module '/var/task/index'",
It turns out when Amazon means zipping, they are expecting a different zip file structure than the one created by the default Mac OS X action of right click and compress the directory. When a Mac compresses a folder, the output is a folder with the files in it. Amazon wants it without that root folder.
Assume you have a source folder called TestSkill with index.js in it. Then you do a right click and Compress “TestSkill” on it. If you run this:
nali-iMacs-iMac:Downloads nali$ zipinfo TestSkill.zip | grep index.js |more
you’ll see this:
16-Dec-30 15:42 TestSkill/index.js
Pretty much what Amazon does not want. Instead, go into the folder and type this:
zip -r foobar.zip package.json *.js node_modules
You want the ‘-r’ so folders in node_modules get added to the zip file as well. Then let’s run the following command to look into the zip file:
nali-iMacs-iMac:Downloads nali$ zipinfo foobar.zip | grep index.js |more
Here is what you should see:
16-Dec-30 15:42 index.js
That is the structure Amazon wants.
Let’s turn this into an npm command. In your package.json, add a script:
"zip": "zip -r foobar.zip package.json *.js node_modules"
When in the folder, running ‘npm run zip’ will create a foobar.zip that can be successfully uploaded to Amazon’s Lambda service and the error “The remote endpoint could not be called, or the response it returned was invalid.” should go away.