aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Bug: Cannot attach to debugger for Apple ARM-Based Chip in VS Code

Open hungnvo opened this issue 11 months ago • 3 comments

Description:

When attempting to attach a debugger to a locally running AWS Lambda function using the SAM CLI on an Apple ARM-based chip (e.g., M1/M2), the debugger keep hanging and never attached. My guess is potentially due to compatibility issues between the debugger, SAM CLI, and Docker on the ARM architecture.

Steps to reproduce:

  1. Create new directory
mkdir -p ~/.vsdbg
  1. Use Docker to download and install vsdbg for the AWS Lambda runtime container with .NET 6 and copy it to local machine
docker run --rm --mount type=bind,src=~/.vsdbg,dst=/vsdbg --entrypoint bash lambci/lambda:dotnet6.0 -c "curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg"
  1. Build SAM
sam build
  1. SAM local start api
sam local start-api --port 1111 --skip-pull-image --debug-port 5858 --debugger-path ~/.vsdbg --warm-containers EAGER
  1. Start launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Core Docker Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "1",

      "pipeTransport": {
        "pipeProgram": "sh",
        "pipeArgs": [ 
          "-c",
          "docker exec -i $(docker ps -q -f publish=5858) ${debuggerCommand}"
        ],
        "debuggerPath": "/tmp/lambci_debug_files/vsdbg",
        "pipeCwd": "${workspaceFolder}",
      },
      "sourceFileMap": {
        "/var/task": "${workspaceFolder}"
      }
    }
  ]
}

I attempted to try both run the launch.json file before and after hitting the endpoint to see if it makes any different.

Observed result:

No breakpoint were hit. the debugger keep hanging and never actually attached.

Expected result:

It will actually hit the breakpoints.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: MacOS Apple M3
  2. sam --version: 1.132
  3. Lambda Runtime: dotnet6
{
  "version": "1.132.0",
  "system": {
    "python": "3.13.1",
    "os": "macOS-15.2-arm64-arm-64bit-Mach-O"
  },
  "additional_dependencies": {
    "docker_engine": "27.3.1",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

hungnvo avatar Jan 09 '25 22:01 hungnvo

Thanks for reporting, to better understand this issue. If you run sam local invoke to invoke the .Net 6 function, will it also hang, or it only happens when you sam local start-api and try to attach a debugger?

roger-zhangg avatar Jan 24 '25 02:01 roger-zhangg

@roger-zhangg The problem is that I want to use sam local start-api so that i don't have to supply the event.json payload for request instead I just need to use Postman to send the request. if I have to create myself a event.json payload, then I can just use the Mocked Lambda Test Tools and it worked just fine for me.

hungnvo avatar Feb 06 '25 17:02 hungnvo

Thank you for the additional information. While we investigate the issue, you may try local invoke and debugging your Lambda functions using AWS Toolkit extension. You can load and save your test event for local invoke right inside of VS Code.

https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/setup-toolkit.html

vicheey avatar Feb 17 '25 08:02 vicheey