使用VS Code(C#)调试dotnet core 2.0 AWS Lambda函数 [英] Debug dotnet core 2.0 AWS Lambda Functions in VS Code (C#)
问题描述
我正在使用VS Code通过dotnet core 2.0 CLI编写Lambda函数.
I'm using VS Code to write Lambda functions using the dotnet core 2.0 CLI.
- VS代码v1.24.1
- dotnet Core CLI v2.1.200
问题
我无法使用在VS Code中编写的功能来使调试器在本地使用.
Problem
I can't get the debugger to work locally with the function I've written in VS Code.
我在var body = request?.Body;
行上放置了一个断点(请参见下面的Function.cs代码块).然后,当我在VS Code的 Debug 选项卡中单击start debugging
按钮时,我得到以下信息:
I place a breakpoint on the line var body = request?.Body;
(See Function.cs code block below). When I then click the start debugging
button in the Debug tab in VS Code, I get the following:
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded 'C:\Users\chris\Documents\Github\tcdevs\resource-it\client-management-lambda\ClientManagement.TestAsyncFunction\test\ClientManagement.TestAsyncFunction.Tests\bin\Debug\netcoreapp2.0\ClientManagement.TestAsyncFunction.Tests.dll'. Symbols loaded.
Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.7\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[49584] ClientManagement.TestAsyncFunction.Tests.dll' has exited with code 0 (0x0).
Function.cs
Lambda函数使用APIGatewayEvents包来接受来自API网关的请求
The Lambda Function uses the APIGatewayEvents package to accept a request from the API Gateway
public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
var body = request?.Body;
// do something asynchronously
return new APIGatewayProxyResponse()
{
Body = JsonConvert.SerializeObject(body),
StatusCode = 200,
Headers = new Dictionary<string, string>{ {"Content-Type", "application/json"} }
};
}
launch.json
我已将其配置为使用Function.cs dll(由vs代码创建的文件正在测试项目中)
I've configured this to use the Function.cs dll's (The file that was created by vs code was hitting the test project)
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (lambda)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/ClientManagement.TestAsyncFunction/bin/Debug/netcoreapp2.0/ClientManagement.TestAsyncFunction.dll",
"args": [],
"cwd": "${workspaceFolder}/src/ClientManagement.TestAsyncFunction",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
}
I've seen this post here:
https://cloudncode.blog/2017/01/24/getting-started-with-writing-and-debugging-aws-lambda-function-with-visual-studio-code/
但是我认为这种方法不适用于dotnet core 2.0.我也做了很多谷歌搜索,几乎没有发现有关如何在VS Code中调试dotnet core 2.0功能的信息.
But I don't think this method will work for dotnet core 2.0. I've also done a lot of googling and have found almost no information on how to debug dotnet core 2.0 functions in VS Code.
推荐答案
好,所以我发现了这一点,这表明目前尚不可能:
OK so I found this, which says it's not possible at the moment:
https://github.com/aws/aws-lambda-dotnet/issues/246
现在转移到NodeJs和Serverless软件包以进行此操作:
Am moving to NodeJs and the Serverless package to do this for now:
https://www.npmjs.com/package/serverless
如果/当dotnet核心发生变化时,将更新此内容
Will update this if / when things change for dotnet core
这篇关于使用VS Code(C#)调试dotnet core 2.0 AWS Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!