0

I am experiencing an issue with AWS Lamda (python 3.8) while trying to debug it locally. AWS SAM Cli commands are working fine while executing from terminal. However, while trying to debug or build from vscode it throws an error. Seems like vscode is picking a different path for python 3.8 version.

Here is the configuration path snapshot from terminal:

mbp$ which python
/usr/bin/python
mbp$ which python3
/usr/local/opt/[email protected]/bin/python3
mbp$ which aws
/usr/local/bin/aws
mbp$ which sam
/usr/local/bin/sam
mbp$ python --version
Python 2.7.16
mbp$ python3 --version
Python 3.8.8

Here is the visual-studio-code log:

2021-02-22 20:53:24 [INFO]: Preparing to debug locally: Lambda "transactions.lambda_handler"
2021-02-22 20:53:24 [INFO]: Building SAM application...
2021-02-22 20:53:24 [INFO]: Running command: (not started) [/Library/Frameworks/Python.framework/Versions/3.8/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctklNIOzG/output --template /Users/mb/REPO/wisyz-transactions/app___vsctk___template.yaml --manifest /tmp/aws-toolkit-vscode/vsctklNIOzG/debug-requirements.txt]
2021-02-22 20:53:24 [WARN]: "sam build" failed: /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml
2021-02-22 20:53:24 [INFO]: Starting SAM application locally
2021-02-22 20:53:24 [INFO]: AWS.running.command
2021-02-22 20:53:24 [ERROR]: Error running command "sam local invoke": spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/sam ENOENT
2021-02-22 20:53:24 [ERROR]: Timeout while waiting for command: "sam local invoke"
2021-02-22 20:53:24 [ERROR]: Failed to run SAM application locally: Timeout while waiting for command: "sam local invoke"
Command stopped: "sam local invoke"
2021-02-22 20:53:24 [INFO]: Waiting for SAM application to start...
2021-02-22 20:53:24 [INFO]: Attaching debugger to SAM application...
2021-02-22 20:53:41 [ERROR]: Retry limit reached while trying to attach the debugger.
2021-02-22 20:53:41 [ERROR]: Unable to attach Debugger. Check AWS Toolkit logs. If it took longer than expected to start, you can still attach.
2021-02-22 21:56:05 [INFO]: Preparing to debug locally: Lambda "transactions.lambda_handler"
2021-02-22 21:56:05 [INFO]: Building SAM application...
2021-02-22 21:56:05 [INFO]: Running command: (not started) [/Library/Frameworks/Python.framework/Versions/3.8/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkIy5kkF/output --template /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml --manifest /tmp/aws-toolkit-vscode/vsctkIy5kkF/debug-requirements.txt]
2021-02-22 21:56:05 [WARN]: "sam build" failed: /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml
2021-02-22 21:56:05 [INFO]: Starting SAM application locally
2021-02-22 21:56:05 [INFO]: AWS.running.command
2021-02-22 21:56:05 [ERROR]: Error running command "sam local invoke": spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/sam ENOENT
2021-02-22 21:56:05 [ERROR]: Timeout while waiting for command: "sam local invoke"
2021-02-22 21:56:05 [ERROR]: Failed to run SAM application locally: Timeout while waiting for command: "sam local invoke"
Command stopped: "sam local invoke"
2021-02-22 21:56:05 [INFO]: Waiting for SAM application to start...
2021-02-22 21:56:05 [INFO]: Attaching debugger to SAM application...
2021-02-22 21:57:04 [ERROR]: Retry limit reached while trying to attach the debugger.
2021-02-22 21:57:04 [ERROR]: Unable to attach Debugger. Check AWS Toolkit logs. If it took longer than expected to start, you can still attach.
4
  • OS: mac Catalina 10.15.4 Commented Feb 23, 2021 at 3:34
  • what is the output when you do python3 --version and python --version? Are you using a virtualenv or venv? Commented Feb 23, 2021 at 3:39
  • Added it in the original post. Also I am not using virtualenv or venv Commented Feb 23, 2021 at 3:48
  • Seems vscode is looking /Library/Frameworks/Python.framework/Versions/3.8/bin/sam path but it does not exist. Not sure why vscode is looking sam cli on that path. Commented Feb 23, 2021 at 3:54

2 Answers 2

1

Another solution that you can try is create a .vscode folder in your project directory and then create a settings.json file inside that directory. Inside the file create

{
    "python.pythonPath": "<python path>",
}

replace the python path with the path to your python binary file.

Sign up to request clarification or add additional context in comments.

Comments

0

It worked once after setting the python path /usr/local/opt/[email protected]/bin/python3 in vscode View > command palette > Python: select interpreter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.