aws / aws/aws-sam-cli

SAM local api - VSCode launch.json - Debugger not starting

Open
#5,932 1 comment 0 reactions 0 assignees View on GitHub
area/debugging
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:
I'm trying to start an APIUnable to start/attach to the debugger on VSCode.

### Steps to reproduce:
Run VSCode debugger:
![image](https://github.com/aws/aws-sam-cli/assets/120570819/e4e48833-3b92-4c6e-879f-aac8ed2fd588)

With the folowing config:
```{
"version": "0.2.0",
"configurations": [
{
"debugServer": 60000,
"type": "aws-sam",
"request": "direct-invoke",
"name": "AWS-SAM",
"invokeTarget": {
"target": "api",
"templatePath": "template.yaml",
"logicalId": "LambdaFunctionApp"
},
"api": {
"httpMethod": "get",
"path": "/test",
},
"sam": {
"localArguments": [
"--debug",
"--debugger-path",
"/tmp",
"--debug-function",
"LambdaFunctionApp",
"--debug-port",
"60000",
"--warm-containers",
"EAGER"
]
},
"aws": {}
}
]
}
```

### Observed result:
Requests to local endpoint: OK
Debugger attached: NOK *Debugger not attached*
```
2023-09-13 18:29:51 [INFO]: Cache is invalid, running build and copying resources for following functions (LambdaFunctionApp)
Building codeuri: /LambdaFunctionApp runtime: dotnet6 metadata: {} architecture: x86_64 functions: LambdaFunctionApp

2023-09-13 18:29:51 [INFO]: Running DotnetCliPackageBuilder:GlobalToolInstall

2023-09-13 18:29:51 [INFO]:

2023-09-13 18:29:54 [INFO]: Tool 'amazon.lambda.tools' was reinstalled with the latest stable version (version '5.8.0').
Running DotnetCliPackageBuilder:RunPackageAction

2023-09-13 18:30:37 [INFO]: Amazon Lambda Tools for .NET Core applications (5.8.0)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet

Executing publish command
Deleted previous publish folder
... invoking 'dotnet publish', working folder '/LambdaFunctionApp/bin/Debug/net6.0/publish'
... dotnet publish "/LambdaFunctionApp" --output "/LambdaFunctionApp/bin/Debug/net6.0/publish" --configuration "Debug" --framework "net6.0" --runtime linux-x64 /p:GenerateRuntimeConfigurationFiles=true --self-contained False
... publish: Microsoft (R) Build Engine version 17.0.1+b177f8fa7 for .NET
... publish: Copyright (C) Microsoft Corporation. All rights reserved.
... publish: Determining projects to restore...
... publish: All projects are up-to-date for restore.
...
Created publish archive (/tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp/Integration.Main.zip).
Lambda project successfully packaged: /tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp/Integration.Main.zip

2023-09-13 18:30:47 [INFO]:
Build Succeeded

2023-09-13 18:30:47 [INFO]:
Built Artifacts : ../../../../tmp/aws-toolkit-vscode/vsctkx3as5F/output
Built Template : ../../../../tmp/aws-toolkit-vscode/vsctkx3as5F/output/template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke -t ../../../../tmp/aws-toolkit-vscode/vsctkx3as5F/output/template.yaml
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided --template-file ../../../../tmp/aws-toolkit-vscode/vsctkx3as5F/output/template.yaml

2023-09-13 18:30:48 [INFO]: Build complete.
2023-09-13 18:30:48 [INFO]: Installing .NET Core Debugger to /LambdaFunctionApp/.vsdbg...
Info: Last installed version of vsdbg is '17.7.10808.2'
Info: VsDbg is up-to-date
Info: Using vsdbg version '17.7.10808.2'
Using arguments
Version : 'latest'
Location : '/LambdaFunctionApp/.vsdbg'
SkipDownloads : 'true'
LaunchVsDbgAfter : 'false'
RemoveExistingOnUpgrade : 'false'
Info: Skipping downloads
2023-09-13 18:30:49 [INFO]: Sending request to local API: http://127.0.0.1:5858/test?
2023-09-13 18:30:49 [INFO]: Starting SAM application locally
2023-09-13 18:30:50 [INFO]: AWS.running.command
2023-09-13 18:30:50,941 | No config file found in this directory.
2023-09-13 18:30:50,941 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/tmp/aws-toolkit-vscode/vsctkx3as5F/output/samconfig.toml'
2023-09-13 18:30:50,941 | Config file location: /tmp/aws-toolkit-vscode/vsctkx3as5F/output/samconfig.toml
2023-09-13 18:30:50,941 | Config file '/tmp/aws-toolkit-vscode/vsctkx3as5F/output/samconfig.toml' does not exist
2023-09-13 18:30:50,981 | Using config file: samconfig.toml, config environment: default
2023-09-13 18:30:50,981 | Expand command line arguments to:
2023-09-13 18:30:50,981 | --template_file=/tmp/aws-toolkit-vscode/vsctkx3as5F/output/template.yaml --port=5858 --debug_port=(5859, 60000) --debugger_path=/tmp --debug_function=LambdaFunctionApp --warm_containers=EAGER --host=127.0.0.1 --static_dir=public --layer_cache_basedir=/home/silvio/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2023-09-13 18:30:51,126 | local start-api command is called
2023-09-13 18:30:51,131 | No Parameters detected in the template
2023-09-13 18:30:51,157 | Sam customer defined id is more priority than other IDs. Customer defined id for resource LambdaFunctionApp is LambdaFunctionApp
2023-09-13 18:30:51,157 | There is no customer defined id or cdk path defined for resource ServerlessHttpApi, so we will use the resource logical id as the resource id
2023-09-13 18:30:51,159 | 0 stacks found in the template
2023-09-13 18:30:51,161 | No Parameters detected in the template
2023-09-13 18:30:51,182 | Sam customer defined id is more priority than other IDs. Customer defined id for resource LambdaFunctionApp is LambdaFunctionApp
2023-09-13 18:30:51,182 | There is no customer defined id or cdk path defined for resource ServerlessHttpApi, so we will use the resource logical id as the resource id
2023-09-13 18:30:51,183 | 2 resources found in the stack
2023-09-13 18:30:51,183 | Found Serverless function with name='LambdaFunctionApp' and CodeUri='LambdaFunctionApp'
2023-09-13 18:30:51,183 | --base-dir is not presented, adjusting uri LambdaFunctionApp relative to /tmp/aws-toolkit-vscode/vsctkx3as5F/output/template.yaml
2023-09-13 18:30:51,184 | watch resource /tmp/aws-toolkit-vscode/vsctkx3as5F/output/template.yaml
2023-09-13 18:30:51,184 | Create Observer for resource /tmp/aws-toolkit-vscode/vsctkx3as5F/output/template.yaml with recursive True
2023-09-13 18:30:51,186 | watch resource /tmp/aws-toolkit-vscode/vsctkx3as5F/output/template.yaml's parent /tmp/aws-toolkit-vscode/vsctkx3as5F/output
2023-09-13 18:30:51,186 | Create Observer for resource /tmp/aws-toolkit-vscode/vsctkx3as5F/output with recursive False
2023-09-13 18:30:51,192 | Initializing the lambda functions containers.
2023-09-13 18:30:51,192 | Async execution started
2023-09-13 18:30:51,193 | Invoking function functools.partial(.initialize_function_container at 0x7f4fb5528ae0>, Function(function_id='LambdaFunctionApp', name='LambdaFunctionApp', functionname='LambdaFunctionApp', runtime='dotnet6', memory=1024, timeout=100, handler='Integration.Main', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp', environment={'Variables': {'SAMPLE_TABLE': 'SampleTable'}}, rolearn=None, layers=[], events={'ProxyResource': {'Type': 'HttpApi', 'Properties': {'PayloadFormatVersion': '2.0', 'Path': '/test', 'Method': 'ANY', 'ApiId': 'ServerlessHttpApi'}}}, metadata={'SamResourceId': 'LambdaFunctionApp'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, function_build_info=, stack_path='', runtime_management_config=None))
2023-09-13 18:30:51,194 | Waiting for async results
2023-09-13 18:30:51,198 | Loading AWS credentials from session with profile 'None'
2023-09-13 18:30:51,220 | Resolving code path. Cwd=/tmp/aws-toolkit-vscode/vsctkx3as5F/output, CodeUri=/tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp
2023-09-13 18:30:51,220 | Resolved absolute path to code is /tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp
2023-09-13 18:30:51,441 | watch resource /tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp
2023-09-13 18:30:51,441 | Create Observer for resource /tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp with recursive True
2023-09-13 18:30:51,443 | watch resource /tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp's parent /tmp/aws-toolkit-vscode/vsctkx3as5F/output
2023-09-13 18:30:51,445 | Code /tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp is not a zip/jar file
2023-09-13 18:30:55,363 | Local image is up-to-date
2023-09-13 18:30:55,371 | Using local image: public.ecr.aws/lambda/dotnet:6-rapid-x86_64.

2023-09-13 18:30:55,371 | Mounting /tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp as /var/task:ro,delegated, inside runtime container
2023-09-13 18:30:55,907 | Async execution completed
2023-09-13 18:30:55,908 | Containers Initialization is done.
2023-09-13 18:30:55,908 | Found '1' API Events in Serverless function with name 'LambdaFunctionApp'
2023-09-13 18:30:55,908 | Detected Inline Swagger definition
2023-09-13 18:30:55,908 | Parsing Swagger document using 3.0 specification
2023-09-13 18:30:55,908 | Lambda function integration not found in Swagger document at path='/test' method='x-amazon-apigateway-any-method'
2023-09-13 18:30:55,909 | Found '0' APIs in resource 'ServerlessHttpApi'
2023-09-13 18:30:55,909 | Found '0' authorizers in resource 'ServerlessHttpApi'
2023-09-13 18:30:55,909 | Removed duplicates from '0' Explicit APIs and '1' Implicit APIs to produce '1' APIs
2023-09-13 18:30:55,909 | 1 APIs found in the template
2023-09-13 18:30:55,912 | Mounting LambdaFunctionApp at http://127.0.0.1:5858/test [DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT]
2023-09-13 18:30:55,912 | You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. If you used sam build before running local commands, you will need to re-run sam build for the changes to be picked up. You only need to restart SAM CLI if you update your AWS SAM template
2023-09-13 18:30:55,912 | Localhost server is starting up. Multi-threading = False
2023-09-13 18:30:55 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5858
2023-09-13 18:30:55 Press CTRL+C to quit
2023-09-13 18:30:56,073 | Constructed Event Version 2.0 to invoke Lambda. Event: {'version': '2.0', 'routeKey': 'GET /test', 'rawPath': '/test', 'rawQueryString': '', 'cookies': [], 'headers': {'User-Agent': 'got (https://github.com/sindresorhus/got)', 'Content-Type': 'application/json', 'Accept-Encoding': 'gzip, deflate, br', 'Host': '127.0.0.1:5858', 'Connection': 'close', 'X-Forwarded-Proto': 'http', 'X-Forwarded-Port': '5858'}, 'requestContext': {'accountId': '123456789012', 'apiId': '1234567890', 'http': {'method': 'GET', 'path': '/test', 'protocol': 'HTTP/1.1', 'sourceIp': '127.0.0.1', 'userAgent': 'Custom User Agent String'}, 'requestId': '3a4480e4-7779-4b5c-9a4b-cd6f296b3207', 'routeKey': 'GET /test', 'stage': '$default', 'time': '13/Sep/2023:17:30:51 +0000', 'timeEpoch': 1694626251, 'domainName': 'localhost', 'domainPrefix': 'localhost'}, 'body': '', 'pathParameters': {}, 'stageVariables': None, 'isBase64Encoded': False}
2023-09-13 18:30:56,074 | Found one Lambda function with name 'LambdaFunctionApp'
2023-09-13 18:30:56,074 | Invoking Integration.Main (dotnet6)
2023-09-13 18:30:56,074 | Resolving code path. Cwd=/tmp/aws-toolkit-vscode/vsctkx3as5F/output, CodeUri=/tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp
2023-09-13 18:30:56,074 | Resolved absolute path to code is /tmp/aws-toolkit-vscode/vsctkx3as5F/output/LambdaFunctionApp
2023-09-13 18:30:56,079 | Reuse the created warm container for Lambda function 'LambdaFunctionApp'
2023-09-13 18:30:56,082 | Lambda function 'LambdaFunctionApp' is already running
2023-09-13 18:30:56,082 | Setting up SIGTERM interrupt handler
START RequestId: 364bbcba-686f-4a98-b92e-03aced915308 Version: $LATEST
END RequestId: 364bbcba-686f-4a98-b92e-03aced915308
REPORT RequestId: 364bbcba-686f-4a98-b92e-03aced915308 Init Duration: 0.29 ms Duration: 640.81 ms Billed Duration: 641 ms Memory Size: 1024 MB Max Memory Used: 1024 MB
2023-09-13 18:30:57 127.0.0.1 - - [13/Sep/2023 18:30:57] "GET /test HTTP/1.1" 200 -
```

### Expected result:
Expecting the VSCode Debuger to attach to the .NET app running inside the container.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
OS: Ubuntu 22.04
IDE: VSCode 1.82.1
```
{
"version": "1.95.0",
"system": {
"python": "3.11.3",
"os": "Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.35"
},
"additional_dependencies": {
"docker_engine": "24.0.6",
"aws_cdk": "Not available",
"terraform": "1.5.2"
},
"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"
]
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.