aws-sam-cli: Can't debug using vscode v1.25, Unable to open 'index.js': File not found
Description:
I’m trying to debug a lambda with sam cli. It starts up the docker container, and then waits for me to attach a debugger. When I try to attach, vscode pops up a warning:
Unable to open 'index.js': File not found (file:///c:/Users/esty.heller/Documents/Dev/benmanagesoftware/lambda/runtime/node_modules/awslambda/index.js).
And then it just stops and waits, can’t do anything except disconnect and let the function run.
Just running the function with sam local invoke works fine.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc) Windows 10, Docker version 18.03.1-ce, build 9ee9f40 (using linux containers), latest vscode
Output of sam --version
:
SAM CLI, version 0.4.0
Optional Debug logs:
$ sam local invoke -e event-create.json -d 5858 CreateUrl
2018-07-15 11:17:47 Invoking create-url.handler (nodejs8.10)
2018-07-15 11:17:47 Found credentials in shared credentials file: ~/.aws/credentials
Fetching lambci/lambda:nodejs8.10 Docker container image......
2018-07-15 11:17:49 Mounting C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener as /var/task:ro inside runtime container
Debugger listening on ws://0.0.0.0:5858/3e08373e-2480-470f-9eed-d7fe2651cae0
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
At this point, I try to attach using my launch config:
{
"name": "Attach to Sam Local",
"type": "node",
"request": "attach",
"port": 5858,
"protocol": "inspector",
"address": "localhost",
"localRoot": "${workspaceRoot}/",
"remoteRoot": "/var/task/"
}
And I get a popup warning Unable to open 'index.js': File not found (file:///c:/Users/esty.heller/Documents/Dev/benmanagesoftware/lambda/runtime/node_modules/awslambda/index.js).
and it won’t attach.
Here is my template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 300
Runtime: nodejs8.10
MemorySize: 512
Resources:
CreateUrl:
Type: AWS::Serverless::Function
Properties:
Handler: create-url.handler
Role: arn:aws:iam::933503113720:role/benmanage-lambda-api-dev
FunctionName: url-shortener-create-url-dev
Here is the create-url.js
exports.handler = async event => {
console.log(JSON.stringify(process.env, null, '\t'));
return event;
};
and here is event-create.json
{
"url": "https://hashids.org",
"metaData": {
"email": "test@example.com",
"phone": "+13145291389"
}
}
Add --debug flag to command you are running
$ sam local invoke -e event-create.json -d 5858 CreateUrl --debug
2018-07-15 11:40:49 local invoke command is called
2018-07-15 11:40:49 1 resources found in the template
2018-07-15 11:40:49 Found Serverless function with name='CreateUrl' and CodeUri='.'
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 http://localhost:None "GET /v1.35/_ping HTTP/1.1" 200 2
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Found one Lambda function with name 'CreateUrl'
2018-07-15 11:40:49 Invoking create-url.handler (nodejs8.10)
2018-07-15 11:40:49 Environment variables overrides data is standard format
2018-07-15 11:40:49 Loading AWS credentials from session with profile 'None'
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable config_file from defaults.
2018-07-15 11:40:49 Loading variable credentials_file from defaults.
2018-07-15 11:40:49 Loading variable data_path from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable credentials_file from defaults.
2018-07-15 11:40:49 Loading variable config_file from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable metadata_service_timeout from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable metadata_service_num_attempts from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Looking for credentials via: env
2018-07-15 11:40:49 Looking for credentials via: assume-role
2018-07-15 11:40:49 Looking for credentials via: shared-credentials-file
2018-07-15 11:40:49 Found credentials in shared credentials file: ~/.aws/credentials
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable region from config file with value 'us-east-1'.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable region from config file with value 'us-east-1'.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable profile from defaults.
2018-07-15 11:40:49 Loading variable region from config file with value 'us-east-1'.
2018-07-15 11:40:49 Resolving code path. Cwd=C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener, CodeUri=.
2018-07-15 11:40:49 Resolved absolute path to code is C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener
2018-07-15 11:40:49 Code C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener is not a zip/jar file
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 http://localhost:None "GET /v1.35/images/lambci/lambda:nodejs8.10/json HTTP/1.1" 200 None
2018-07-15 11:40:49 Looking for auth config
2018-07-15 11:40:49 No auth config in memory - loading from filesystem
2018-07-15 11:40:49 Trying paths: ['C:\\Users\\esty.heller\\.docker\\config.json', 'C:\\Users\\esty.heller\\.dockercfg']
2018-07-15 11:40:49 No config file found
2018-07-15 11:40:49 Looking for auth entry for 'docker.io'
2018-07-15 11:40:49 No entry found
2018-07-15 11:40:49 No auth config found
2018-07-15 11:40:52 http://localhost:None "POST /v1.35/images/create?tag=nodejs8.10&fromImage=lambci%2Flambda HTTP/1.1" 200 None
Fetching lambci/lambda:nodejs8.10 Docker container image......
2018-07-15 11:40:52 Mounting C:\Users\esty.heller\Documents\Dev\benmanagesoftware\lambda\url-shortener as /var/task:ro inside runtime container
2018-07-15 11:40:52 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 90
2018-07-15 11:40:52 http://localhost:None "GET /v1.35/containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/json HTTP/1.1" 200 None
2018-07-15 11:40:52 http://localhost:None "GET /v1.35/containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/json HTTP/1.1" 200 None
2018-07-15 11:40:52 http://localhost:None "POST /v1.35/containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/start HTTP/1.1" 204 0
2018-07-15 11:40:52 Setting up SIGTERM interrupt handler
2018-07-15 11:40:52 http://localhost:None "GET /v1.35/containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/json HTTP/1.1" 200 None
2018-07-15 11:40:52 http://localhost:None "POST /containers/79c711637027c81c8f952b4f9b255a2e5ab5378468607ec784c331e6306c5d20/attach?stream=1&stdin=0&logs=1&stderr=1&stdout=1 HTTP/1.1" 101 0
Debugger listening on ws://0.0.0.0:5858/0d8e8c68-dc15-4b74-b038-e0b83ca1cf1c
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 16 (7 by maintainers)
I also would like to add a walk-around. If, in launch.json, both “localRoot” and “remoteRoot” is properly set, especially “localRoot” is set as the root of the source, corresponding to the “codeUri” property in template, you can just set a breakpoint in the code, ignore the error message (although a bit of annoying to see it there) and press F5 or click the Continue (play) button, and execution will pause at the breakpoint and you can trace your code. It’s just you cannot trace what’s inside the code from that “awslambda/index.js”.
For example, in the example project I’m working on, “CodeUri: src/” is in “template.yaml” in the properties of the lambda function, and “localRoot”: “${workspaceRoot}/src” is in the launch.json to match the codeUri.
Or, if breakpoint does not work, you can still use the “debugger” statement to break the execution.