aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.49k stars 418 forks source link

VS Code Local Invoke Debugger times out when using using log-file argument #5265

Open MorganTDicks opened 3 months ago

MorganTDicks commented 3 months ago

Problem

I'm trying to run the vs code debugger for a local lambda invocation. It was working fine but when I added the log-file argument "localArguments" property to produce logs locally the invocation started timing out. I have noticed that the log file is created with the following content:

START RequestId: ce7a3621-0262-4d85-b899-26c78ced885b Version: $LATEST Prepending Lambda task root to path: /var/task Starting debugger... Debugger waiting for client...

but the function itself does not run.

I am able to get the expected result when using the sam cli, The logs are produced and the function runs successfully with the following command: sam local invoke --log-file tests/logs/stdout.log --event tests/events/sqs-event.json PolicyIngestionFunction

Steps to reproduce the issue

launch.json:

 {
    "version": "0.2.0",
    "configurations": [
         {
             "type": "aws-sam",
            "request": "direct-invoke",
             "name": "policy_batch_ingestion:app.lambda_handler (python3.9)",
             "invokeTarget": {
                 "target": "code",
                 "projectRoot": "${workspaceFolder}/SAM/step_functions/policy-sync/functions/policy_batch_ingestion",
                 "lambdaHandler": "app.lambda_handler"
             },
             "lambda": {
                 "runtime": "python3.9",
                 "payload": {
                     "path": "${workspaceFolder}/SAM/step_functions/policy-sync/tests/events/sqs-event.json"
                 },
                 "environmentVariables": {}
             },
             "sam": {
                 "localArguments": ["--log-file","${workspaceFolder}/SAM/step_functions/policy-sync/tests/logs/stdout.log"]
             }
         },
     ]
 }

Directory Tree:

workspaceFolder ┣ /SAM ┃ ┗ /step_functions ┃ ┗ /policy-sync ┃ ┣ /functions ┃ ┃ ┣ /policy_batch_ingestion ┃ ┃ ┃ ┣ init.py ┃ ┃ ┃ ┣ app.py ┃ ┃ ┃ ┗ requirements.txt ┃ ┃ ┗ init.py ┃ ┣ /statemachine ┃ ┃ ┗ policySync.asl.json ┃ ┣ /tests ┃ ┃ ┣ /events ┃ ┃ ┃ ┗ sqs-event.json ┃ ┃ ┣ /logs ┃ ┃ ┃ ┗ stdout.log ┃ ┃ ┣ init.py ┃ ┃ ┗ requirements.txt ┃ ┣ .gitignore ┃ ┣ README.md ┃ ┣ init.py ┃ ┣ samconfig.toml ┃ ┗ template.yaml ┣ .gitignore ┗ README.md

Expected behavior

Expected behavior is that the function would run as if I had triggered it with the cli but with debugging functionality.

System details

justinmk3 commented 2 months ago

Does the AWS Toolkit vscode output channel show messages? AWS Toolkit looks for sam output to decide if sam is stuck, since there is no other way to check for activity. If sam cli's output is redirected (by --log-file), then this could result in AWS Toolkit deciding that sam cli is unresponsive/inactive.

The aws.samcli.lambdaTimeout setting controls how long AWS Toolkit waits for the "sam build" command. Does increasing this setting resolve your issue?

image

Related code: https://github.com/aws/aws-toolkit-vscode/blob/e88e482a9e7a7819fab39c1aa5f41c3286fd2825/packages/core/src/shared/sam/localLambdaRunner.ts#L299