【发布时间】:2018-11-13 21:29:16
【问题描述】:
使用 Amazon Lambda 函数模板编写了一个 .NET core 2 Web api 应用程序。使用邮递员编写了一些测试电话。 .NET 核心代码在本地运行时一切正常。将 .NET 核心代码上传到 Lambda 函数,修改邮递员以调用该 URL。在 Lambda 函数中运行的 .NET 代码一切正常 - 使用 Postman 在本地调用。
现在的要求是从 aws codepipline 调用 Lambda 函数内的 .NET 核心代码。无法让它工作
当 Postman 调用 lambda 函数时 - 我在 cloudwatch 日志中看到了这一点:
Lambda Deserialize Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest:
{
"resource": "/{proxy+}",
"path": "/api/Rds/InstanceStatus",
"httpMethod": "GET",
这个电话有效! 我的 .NET 核心代码记录以下内容
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.Body = null
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.HttpMethod = GET
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.Path = /api/Rds/InstanceStatus
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.Resource = /{proxy+}
注意 - 您可以看到在调用我的 .NET 核心代码之前填充了 LambdaEntryPoint 对象
当我尝试从 codepipeline 中复制相同的调用时 - 我在 cloudwatch 日志中看到了这一点:
Lambda Deserialize Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest:
{
"CodePipeline.job": {
"id": "379d05fe-ec03-4ec9-8bce-59f31901aeb8",
"accountId": "109319094079",
"data": {
"actionConfiguration": {
"configuration": {
"FunctionName": "NexuIntRestServerless2-AspNetCoreFunction-T8Q5XCCN0FIC",
"UserParameters": "{\"resource\":\"/{proxy+}\",\"path\":\"/api/Rds/InstanceStatus\",\"httpMethod\":\"GET\"}"
}
},
我试图重现代码管道用户参数中的参数。但是,我的 .NET 核心代码日志如下所示:
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.Body = null
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.HttpMethod = null
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.Path = null
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.Resource = null
LOG_LEVEL_TRACE,Nexus.Rds.Restore.dll,1.0.0.0,Nexus.Rds.Restore.LambdaEntryPoint,FunctionHandlerAsync,APIGatewayProxyRequest.RequestContext = null
注意:LambdaEntryPoint 现在为 null,并引发异常 - 我假设是因为 .NET 核心不知道如何路由调用:
One or more errors occurred. (Object reference not set to an instance of an object.): AggregateException
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayProxyRequest apiGatewayRequest, ILambdaContext lambdaContext)
at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.<FunctionHandlerAsync>d__13.MoveNext()
关于如何从 Codepipeline 中调用 Lambda 函数有什么想法吗?
谢谢
【问题讨论】:
标签: c# .net-core aws-lambda aws-codepipeline