aws-toolkit-vscode: Debugger not working invalid (or missing) template file
Describe the bug
Lambda debug does not works, when press to “Start Debugging” button an error appear:
Invalid (or missing) template file (path must be workspace-relative, or absolute):
To Reproduce
- Open template.yaml
- Press on button “Add Debug Configuration”
- Configure Lambda payload and environmentVariables (optional)
- Press on “Start Debugging”
The .vscode/launch.json
file look like this:
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "MyFunction",
"invokeTarget": {
"target": "template",
"templatePath": "template.yaml",
"logicalId": "MyFunction"
},
"lambda": {
"runtime": "nodejs12.x",
"payload": {
"path": "event.json"
},
"environmentVariables": {
"MY_VARIABLE": "test"
}
}
}
]
}
Expected behavior
The Lambda function start locally and VSCode debug is attached to it
Desktop (please complete the following information):
- OS: Linux
- Visual Studio Code Version: 1.51.1
- AWS Toolkit Version: v1.15.0
Additional context
The template file path is correct position, I tested with a simple “stat/file/cat” in terminal and the path is correct, same behaviour using relative or absolute path.
$ file template.yaml
template.yaml: ASCII text
$ file /home/me/project/template.yaml # just an example or my absolute path
template.yaml: ASCII text
The template file is correct, I currently deploy it as SAM application without any issue.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 29 (14 by maintainers)
Commits related to this issue
- Merge pull request #1395 from aws/jpinkney-aws/update-examples-text weaverbird: update examples copy text — committed to aws/aws-toolkit-vscode by awsanakkala 7 months ago
The file el is generated by CDK and I can use it just fine via command line
sam local invoke ...
. But AWS Toolkit does not load it preventing me from using sam cli Debug Configuration. We are starting the sam local invoke debugger with a VS Code preLaunchTask and attaching to the debugger to workaround this problem but it would be nice for AWS Toolkit to support the same templates sam cli doesWe should surface this somehow, will keep this open to track that.
ah-ah! experienced something similar to @dudutwizer:
here what I set in my template file:
I’m sorry, I hadn’t noticed the error message before activating the verbose module logs and searching for them. I use the global field a lot, almost all common configurations and, for the runtime, I use it by default on new templates… that’s the reason why I had this error for basically all my projects 😄.
Just moved
Runtime
configuration from global to function’s properties and the error is gone, thank you everyone!definitely a duplicate of #1211
@dudutwizer thanks! That particular issue is tracked in https://github.com/aws/aws-toolkit-vscode/issues/1211
And that confirms that this issue is related to “invalid” template.yaml.
So we need to surface this somehow. Alternatively we could add “invalid” template.yaml’s to the registry, and then surface the validation errors at appropriate times (e.g. when used in a launch config).
I had the same issue, and I solved it by moving the handler definition from the global to the resource level. instead of
to
Hi @justinmk3,
just tested with 1.18.0 version (the latest one) and the error still exist. I did the test that you suggested and it returns
true
.Also did a test with
lstatSync
and it works:And a final test with
readFileSync
, it can correct read the entire file content:Installed the version you linked and I correctly see the new version number:
unfortunately did not solve the problem, same error doing the same tests as before (VSCode restart and file saving included)
Can you confirm that you have
/home/me/project/
open in vscode as a workspace? The Toolkit resolves relative paths against the current workspace. Can you share a screenshot of your VSCode File Explorer tree?For reference: the contents of the template.yaml don’t matter for this error, only the workspace. If we can figure out what’s different about the state of your VSCode session, we take that case into consideration when resolving the full path to template.yaml.