alexa-skills-kit-sdk-for-nodejs
alexa-skills-kit-sdk-for-nodejs copied to clipboard
Local Debug Error: WebSocket error: Unexpected server response: 401
I'm submitting a...
[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:
Expected Behavior
Test and debug custom Alexa Skill in a local environment as described by the documentation:
- https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/tree/2.0.x/ask-sdk-local-debug
- https://developer.amazon.com/en-US/docs/alexa/ask-toolkit/vs-code-testing-simulator.html
Current Behavior
Receiving error
WebSocket error: Unexpected server response: 401
WebSocket is closed: CloseEvent {target: WebSocket, type: 'close', wasClean: false, reason: '', code: 1006}
when start debugging.
Possible Solution
Steps to Reproduce (for bugs)
Since error 401 should means 'Unauthorized', I started a fresh project.
1. Clone a skill
Clone a fresh skill using VS Code Extension Alexa Skills Toolkit.
2. Clone a sample skill and install packages (nodejs)
Create a lambda folder. Download and move content from Hello World Sample to the lambda folder.
Run the following commands to install all required packages (inside lambda folder):
npm install
npm install --save ask-sdk-model@^1.29.0
npm install --save-dev ask-sdk-local-debug
3. Set up environment
Follow Set up the test environment instructions to create and set up the launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Alexa Skill (Node.js)",
"type": "node",
"request": "launch",
"program": "${command:ask.debugAdapterPath}",
"args": [
"--accessToken",
"${command:ask.accessToken}",
"--skillId",
"${command:ask.skillIdFromWorkspace}",
"--handlerName",
"handler",
"--skillEntryFile",
"${workspaceFolder}/lambda/index.js",
"--region",
"EU"
]
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
4. Start Debugging
Select Debug Alexa Skill (Node.js) and start debugging.
C:\Program Files\nodejs\node.exe .\lambda\node_modules\ask-sdk-local-debug\dist\LocalDebuggerInvoker.js --accessToken Atza|XXXXXX --skillId amzn1.ask.skill.XXXXX --handlerName handler --skillEntryFile D:\<mypath>/lambda/index.js --region EU
Region chosen: EU
WebSocket error: Unexpected server response: 401
WebSocket is closed: CloseEvent {target: WebSocket, type: 'close', wasClean: false, reason: '', code: 1006}
5. Get a new access token
Run command ask util generate-lwa-tokens --scopes alexa::ask:skills:debug to get a new access token. Replace (hard-coding temporarily) ${command:ask.accessToken} with the new fresh access token. Start debugging. Same error.
6. Configure profile
Try to re-configure profile with ask configure --profile XXXX. Reload VS Code. Start Debugging. Same error.
Context
I am trying to test and debug Alexa skill from VS Code. Thing is, the debugger used to work some days ago (and always worked). My colleagues are in the same situation. It seems that it just stopped working suddenly. Getting new access tokens should exclude a problem with authorization.
Note that we are trying to use the debugger from EU region.
Your Environment
- ASK SDK for Node.js used: 2.30.5
- Operating System and version: Windows 11 Home V 23H2
Node.js and NPM Info
- Node.js version used for development: v18.20.4
- NPM version used for development: 10.7.0