Open austinben opened 2 years ago
This is because of a change with debugpy
See here: https://github.com/aws/aws-sam-cli/issues/3347#issuecomment-942416740
Use one of the solutions and you should be good.
https://github.com/aws/aws-sam-cli/issues/3347 was closed:
Closing the issue as there is a workaround and we can't actually fix the issue from SAM CLI
Reopening this until https://github.com/microsoft/debugpy/issues/750 is resolved or we decide if it's feasible to mitigate this or provide better messaging.
Describe the bug
I have a AWS Lambda function that I am attempting to step-through debug with VSCode. I am running into an issue where the behaviour of the debugger and VSCode does not make sense, claiming it cannot resolve non-existent files from paths that it should not be looking for these packages at.
The lambda function has been tested locally using the
aws-sam-cli
'ssam build
andsam local invoke
functionality. The lambda correctly takes a JSON event with-e
, and returns the expected response. This has been tested with the following setup for its SAM template:The
launch.json
, referenced from https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps-run-debug-config-ref.html, is configured as follows:When attempting to debug via
Run > Start Debugging
in VSCode, the docker build completes successfully, and the debugger attaches as per the AWS Toolkit logs. The Dockerfile in question is as follows:After setting a breakpoint on the first line of
index.py
, which isimport time
, the debugger stops as expected and all is fine. When I begin to step through the lambda code, there is another import from one of my modules where I am importingfrom elasticsearch import Elasticsearch
. This is where the first issue appears. VSCode throws an error window in the bottom right with the following message:Where
lambdacode
is the root directory containing the lambda code, module directories, requirement.txt, etc.I am unable to determine why the debugger is looking for these packages at this workspace path. It seems as if the debugger is not utilizing the docker container at all, since it is looking locally for the packages. For reference,
urllib3
is installed system wide on my machine, installed in my virtual environment, and installed in the docker container in question.Why is the debugger attempting to look exactly here in my workspace folder for the package, and is not utilizing the docker container? Is this a behaviour that I can change somehow? Even after stepping over this import and ignoring the error, there continues to be identical errors for other libraries such as
dateutil
etc, which are also installed everywhere that makes sense.To Reproduce
To reproduce the same error, which occurs from the elasticsearch import:
sam init
from elasticsearch import Elasticsearch
to app.py and addelasaticsearch
torequirements.txt
Expected behavior
The debugger to be able to step through the lambda in the built docker environment.
Desktop (please complete the following information):