aws-toolkit-jetbrains icon indicating copy to clipboard operation
aws-toolkit-jetbrains copied to clipboard

PyCharm Fail on Debug SAM Hello World

Open guaido79 opened this issue 1 year ago • 9 comments

Describe the bug Running Local Debug on unmodified hello world project will throw error:

Invoking app.lambda_handler (python3.9)
Local image is up-to-date
Using local image: public.ecr.aws/lambda/python:3.9-rapid-x86_64.

Mounting /Users/guimagni/dev/workspaces/aws/phyton/LambdaPyhton03/.aws-sam/build/Function as /var/task:ro,delegated inside runtime container
START RequestId: 2a4799b6-4241-45db-9440-ff9c920fbb26 Version: $LATEST
/var/lang/bin/python3.9: can't open file '/tmp/lambci_debug_files/pydevd.py': [Errno 2] No such file or directory
24 Mar 2023 16:28:16,598 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 2 InvokeID=
/var/lang/bin/python3.9: can't open file '/tmp/lambci_debug_files/pydevd.py': [Errno 2] No such file or directory
END RequestId: 0f43c63d-ed06-4e91-9e51-70a4fc324ca6
REPORT RequestId: 0f43c63d-ed06-4e91-9e51-70a4fc324ca6	Init Duration: 0.19 ms	Duration: 38.85 ms	Billed Duration: 39 ms	Memory Size: 128 MB	Max Memory Used: 128 MB	

To reproduce python3 --version Python 3.9.6

  1. brew install aws/tap/aws-sam-cli
  2. sam init --runtime python3.9 --dependency-manager pip --app-template hello-world --name HelloWorld
  3. Open Project With PyCharm (But same error creating project from IDE)
  4. Debug The default lambda_handler(event, context):
Screenshot 2023-03-24 alle 17 45 11

Expected behavior The application start and hit the breakpoint in the implementation

Screenshots There is an error:

Screenshot 2023-03-24 alle 17 46 41

Your Environment

  • OS: OSX VEntura 13.2.1
  • JetBrains product: PyCharm
  • JetBrains product version: 2022.3.3 (Professional Edition)
  • AWS Toolkit version: 1.62-223
  • SAM CLI version: SAM CLI, version 1.76.0
  • JVM/Python version: Python 3.9.6

Additional context

  1. Already added /Applications/PyCharm.app/ in docker file sharing
  2. If I open the same project with Visual Studio Code it run debug without problem and hit the break point
  3. I do the same operation with IntelliJ Idea with AWS Toolkit, Java or Javascript, and all run without error, hitting breakpoint
  4. I do the same operation with GoLand and all tun without error, hitting breakpoint

guaido79 avatar Mar 24 '23 16:03 guaido79

I am unable to reproduce on a new install of PyCharm Professional 2022.3.3

/var/lang/bin/python3.9: can't open file '/tmp/lambci_debug_files/pydevd.py': [Errno 2] No such file or directory

On Mac, we mount <PYCHARM>/Contents/plugins/python/helpers/pydev into /tmp/lambci_debug_files It seems like pydev isn't in the PyCharm installation for some reason. Have you tried reinstalling PyCharm?

rli avatar Mar 24 '23 17:03 rli

I've a fresh new new installation of PyCharm, downloded to the last version.

The files seems to be there: Screenshot 2023-03-24 alle 20 13 54

It seems that the mount was unsuccessfull.

I've try to delete image from docker causing to build a new one, but still on error.

guaido79 avatar Mar 24 '23 19:03 guaido79

any updates on this issue? I have the same error

yratush avatar Oct 03 '23 09:10 yratush

Do you happen to have any updates on the issue? I am encountering the same error as well.

/var/lang/bin/python3.11: can't open file '/tmp/lambci_debug_files/pydevd.py': [Errno 2] No such file or directory

ISimion avatar Nov 27 '23 09:11 ISimion

Workaround for M1 Mac/Rancher Desktop (lima): https://stackoverflow.com/a/77803515/8751739

naamancampbell avatar Jan 11 '24 23:01 naamancampbell

FYI Docker -> Preferences... -> Resources -> File Sharing add /Applications works.

rumbarum avatar Jan 22 '24 08:01 rumbarum

@rumbarum That is only valid for Docker Desktop, right?

ISimion avatar Jan 31 '24 20:01 ISimion

I got it fixed, by passing --debugger-path /Users/xyz/pydev to SAM CLI local invoke cmd. you may need to check whether pydev is installed, generally in case if PyCharm on MAC it is here at /Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev (PCharm CE) or /Applications/PyCharm CE.app/Contents/plugins/python/helpers/pydev (PyChram professional), however, copy pydev folder to someother location and pass the path to SAM CLI --debugger-path flag.

psi09 avatar Jun 05 '24 13:06 psi09

@rumbarum That is only valid for Docker Desktop, right?

I'm using Rancher Desktop, works for me if running dockerd as container runtime, so it would be right to say that it may work for Docker Desktop as well..

psi09 avatar Jun 05 '24 13:06 psi09