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
768 stars 226 forks source link

Debugger not connecting to local lambda using webstorm + SAM #2849

Open DavidCockerill opened 3 years ago

DavidCockerill commented 3 years ago

When trying to debug a local lambda using webstorm + SAM the debugger does not connect. It looks like the image is getting built but the IDE is not stepping into the code. It just sits there...

One tab shows SAM CLI: running... Running SAM local invoke.

`/usr/local/bin/sam build computeStatusAlarmWorkflow --template /Users/david/Desktop/cloud_services/samTemplates/dev/template-dev.yaml --build-dir /Users/davidl/Desktop/cloud_services/samTemplates/dev/.aws-sam/build
Building codeuri: /Users/david/Desktop/cloud_services/lambdaFunctions/private/computeStatusAlarmWorkflow/computeStatusAlarmWorkflow runtime: nodejs12.x metadata: {} architecture: x86_64 functions: ['computeStatusAlarmWorkflow']
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrc
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided`

The other tab shows

`Invoking computeStatusAlarmWorkflow.lambdaHandler (nodejs12.x)
UtilsLayer is a local Layer in the template
Image was not found.
Building image......................................................................................................................................................................................
Skip pulling image and use local one: samcli/lambda:nodejs12.x-x86_64-9eaa1117c9c7bbf820d.

Mounting /Users/david/Desktop/cloud_services/samTemplates/dev/.aws-sam/build/computeStatusAlarmWorkflow as /var/task:ro,delegated inside runtime container`

And Connecting to localhost:51093

WebStorm 2021.2.2 AWS Toolkit 1.32-212 SAM CLI version 1.33.0 Docker Desktop 4.1.0 macOS Big Sur ver 11.6

DavidCockerill commented 3 years ago

Updates:

I created a small SAM test project and the debugger worked as expected. My app is quite large - 89 lambdas and multiple layers.

When the debugger starts up and doesn't connect I can add/run a config that remotely connects and steps through my lambda.

Edit: I think the issue might be related to the amount of time it takes for SAM to build. My project is large so it takes about 2 min to build. If I comment out a chunk of my yaml template and only build a portion of the project it works. I don't know why the SAM CLI has to loop through all the functions and associated layers to build the one lambda I am debugging. Maybe something in WebStorm times-out waiting for it to finish?

abrooksv commented 3 years ago

There is a max time on connecting the debugger, but that timeout shouldn't include the build time. It does include downloading and building any lambda runtime images.

We do tell SAM to only build a specific function, not sure why the number of functions increases the build time. That would have to be answered by them.

If you can reproduce it, can you check for errors in the idea.log? It can be accessed from the Help menu in the IDE

DavidCockerill commented 3 years ago

2021-10-08 14:36:52,370 [250276740] INFO - rationStore.ComponentStoreImpl - Saving Project(name=cloud_services, containerState=COMPONENT_CREATED, componentStore=/Users/david/Desktop/cloud_services)RunManager took 88 ms 2021-10-08 14:40:45,322 [250509692] WARN - n.process.BaseOSProcessHandler - Process hasn't generated any output for a long time. If it's a long-running mostly idle daemon process, consider overriding OSProcessHandler#readerOptions with 'BaseOutputReader.Options.forMostlySilentProcess()' to reduce CPU usage. Command line: /usr/local/bin/sam local invoke computeStatusAlarmWorkflow --template /Users/david/Desktop/cloud_services/samTemplates/dev/.aws-sam/build/template.yaml --event "/private/var/folders/nj/z8t3_h_927v3r9m_7bt16tyr0000gn/T/[Local] computeStatusAlarmWorkflow-event1111.json" --debug-port 50859 java.lang.Throwable: Process creation: at com.intellij.execution.process.BaseOSProcessHandler.<init>(BaseOSProcessHandler.java:33) at com.intellij.execution.process.OSProcessHandler.<init>(OSProcessHandler.java:48) at com.intellij.execution.process.KillableProcessHandler.<init>(KillableProcessHandler.java:36) at com.intellij.execution.process.ColoredProcessHandler.<init>(ColoredProcessHandler.java:23) at com.intellij.execution.process.KillableColoredProcessHandler.<init>(KillableColoredProcessHandler.java:28) at software.aws.toolkits.jetbrains.utils.execution.steps.CliBasedStep$execute$processHandler$1.<init>(CliBasedStep.kt:49) at software.aws.toolkits.jetbrains.utils.execution.steps.CliBasedStep.execute(CliBasedStep.kt:49) at software.aws.toolkits.jetbrains.utils.execution.steps.Step.run(Step.kt:24) at software.aws.toolkits.jetbrains.utils.execution.steps.ParallelStep$execute$$inlined$forEach$lambda$1.run(ParallelStep.kt:36) at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:265) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665) at java.base/java.lang.Thread.run(Thread.java:829)