使用Amazon Lambda Function模板编写了一个.NET core 2 web api应用程序。用邮递员写了一些测试电话。使用本地运行的.NET核心代码,一切正常。将.NET核心代码上传到Lambda函数,修改postman以调用该URL。使用在Lambda函数中运行的.NET代码一切正常 - 使用Postman在本地调用。
现在的要求是在一个Lambda函数中调用.NET核心代码 - 来自aws codepipline。无法让这个工作
当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\"}"
}
},
我试图在codepipeline用户参数中重现参数。但是,我的.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函数?
由于
答案 0 :(得分:1)
当您通过邮递员调用该功能时,您似乎正在使用API网关。
从API网关调用时,从CodePipeline调用时会有不同的函数输入,因为来自API网关的输入表示HTTP请求与CodePipeline作业。
您的Lambda函数需要设计为处理CodePipeline作业的输入。
有关此作业格式及其使用方式的文档,然后在此处将结果报告回CodePipeline:https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html