aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
733 stars 201 forks source link

aws lambda cannot be debugged locally in WSL2 #2191

Open trixoflow opened 3 years ago

trixoflow commented 3 years ago

Describe the bug Lambda runs fine locally, but when I try to debug is stack on "Picked up _JAVA_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=57546 -XX:MaxHeapSize=2834432k -XX:MaxMetaspaceSize=163840k -XX:ReservedCodeCacheSize=81920k -XX:+UseSerialGC -XX:-TieredCompilation -Djava.net.preferIPv4Stack=true -Xshare:off"

Full log:

"C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2\bin\runnerw64.exe" "C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd" local invoke --template C:\w\flowplayer\lamda\HelloLamda\HelloWorldFunction\src\main\.aws-sam\build\template.yaml --event "C:\Users\trixo\AppData\Local\Temp\[Local] App-event6.json" --debug-port 58776
C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\chevron\renderer.py:73: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if scope is 0:
Invoking helloworld.App (java8.al2)
Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-java8.al2:rapid-1.8.0.

Mounting C:\w\flowplayer\lamda\HelloLamda\HelloWorldFunction\src\main\.aws-sam\build\Function as /var/task:ro,delegated inside runtime container
Picked up _JAVA_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=58776 -XX:MaxHeapSize=2834432k -XX:MaxMetaspaceSize=163840k -XX:ReservedCodeCacheSize=81920k -XX:+UseSerialGC -XX:-TieredCompilation -Djava.net.preferIPv4Stack=true -Xshare:off

I also noticed that there is a docker container created and started, that is not deleted, even when I stop debugging

To reproduce

  1. Create a lambda using intellij
  2. Set the configuration setting a. credentials in aws connection b. region in aws connection c. any text input (I chose API Gateway)
  3. Start debug

Expected behavior To stop at the breaking point inside the RequestHandler

Screenshots

Your Environment

Additional context

abrooksv commented 3 years ago

I do not believe that the WSL2 opened networked ports are visible to Win10 by default.

Are you able to telnet to that debug port from Windows side?

trixoflow commented 3 years ago

hi! thank you for the lighting speed answer. Great idea but didn't work :'(

I opened the port 59775 and I executed the following sam local invoke --template C:\w\flowplayer\lamda\HelloLamda\HelloWorldFunction\src\main\.aws-sam\build\template.yaml --event "C:\Users\trixo\AppData\Local\Temp\[Local] App-event12665.json" --debug-port 59775

I got the usual:

C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\chevron\renderer.py:73: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if scope is 0:
Invoking helloworld.App (java8.al2)
Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-java8.al2:rapid-1.8.0.

Mounting C:\w\flowplayer\lamda\HelloLamda\HelloWorldFunction\src\main\.aws-sam\build\Function as /var/task:ro,delegated inside runtime container
Picked up _JAVA_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=59775 -XX:MaxHeapSize=2834432k -XX:MaxMetaspaceSize=163840k -XX:ReservedCodeCacheSize=81920k -XX:+UseSerialGC -XX:-TieredCompilation -Djava.net.preferIPv4Stack=true -Xshare:off

Then I telnet from windows: "telnet localhost 59775" and I got the following on the other terminal: Debugger failed to attach: timeout during handshake and it continue to be stack.

abrooksv commented 3 years ago

And telnet was able to connect?

Edit: Nvm, it must have since the debug handshake timed out due to telnet not doing the handshake

abrooksv commented 3 years ago

What is the debug host under the SAM CLI tab in the debug run config? That host is populated by the configured docker endpoints in the IDE

trixoflow commented 3 years ago

Yes the telnet succeeded sorry for not mention it clearly. I have uploaded all three tabs in the configuration 2020-11-12 10_16_50-Run_Debug Configurations 2020-11-12 10_17_04-Run_Debug Configurations 2020-11-12 10_17_09-Run_Debug Configurations

trixoflow commented 3 years ago

This looks like this bug: https://github.com/aws/aws-toolkit-eclipse/issues/164

I tried invoking it from terminal, run passes debug freezes. So probably it is not an aws-toolkit-jetbrains issues, but something more generic, should we move this issues on another repository?

amileris commented 1 month ago

What I think happens is that when AWS Toolkit executes sam.cmd local invoke ... - it starts up the Docker container (in my case, of public.ecr.aws/lambda/java:17-rapid-x86_64 image), and then during the container kick-off at some point after the Picked up _JAVA_OPTIONS... message it expects a connection from a remote debugger, but not receiving one, hence it looks as if the debug session hangs. The worst thing is that sometimes it suddenly starts working out of nowhere for a couple of days, and then stops working in the same unexpected manner.

To me it seems like the AWS Toolkit fails to match the debug port provided via --debug-port argument to sam.cmd local invoke ... when creating a debugger connection. I've tested this by manually creating a Remote JVM Debug configuration in IntelliJ on the matching port, and was able to continue with debugging of my Lambda code.

image

I'm running on Windows 10 Pro, Docker in Ubuntu on WSL2, and I've updated the following components in my environment to the latest versions of today with no apparent effect: