.net core 从AWS代码管道操作调用C#.NET核心Lambda

.net core 从AWS代码管道操作调用C#.NET核心Lambda,.net-core,aws-lambda,aws-codepipeline,.net Core,Aws Lambda,Aws Codepipeline,AWS CodePipeline允许您从此处描述的操作调用自定义Lambda 我很难确定如何定义C#Lambda函数,以便从管道访问输入数据 我尝试了无数次,我想这会是类似于下面的东西。我还尝试创建自己的C#类,将输入的JSON数据反序列化到这些类 public void FunctionHandler(Amazon.codepippeline.Model.Job 代码管道,ILambdaContext上下文) 我找到了解决办法。最初,第一步是将lambda函数的输入参数更改为流。然后,我能够将

AWS CodePipeline允许您从此处描述的操作调用自定义Lambda

我很难确定如何定义C#Lambda函数,以便从管道访问输入数据

我尝试了无数次,我想这会是类似于下面的东西。我还尝试创建自己的C#类,将输入的JSON数据反序列化到这些类

public void FunctionHandler(Amazon.codepippeline.Model.Job 代码管道,ILambdaContext上下文)


我找到了解决办法。最初,第一步是将lambda函数的输入参数更改为流。然后,我能够将流转换为字符串,并准确地确定发送给我的内容,例如

然后,基于输入数据,我能够将其映射到一个C#类,该类封装了AWS SDK Amazon.CodePipeline.Model.Job类。它必须映射到json属性“CodePipeline.job”。下面的代码运行正常,我能够检索所有输入值

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
using Amazon.CodePipeline;
using Newtonsoft.Json;
using System.IO;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace lambdaEmptyFunction
{
    public class Function
    {
        public class CodePipelineInput
        {
            [JsonProperty("CodePipeline.job")]
            public Amazon.CodePipeline.Model.Job job { get; set; }
        }

        public void FunctionHandler(CodePipelineInput input, ILambdaContext context)
        {
            context.Logger.LogLine(string.Format("data {0} {1} {2}", input.job.AccountId, input.job.Data.InputArtifacts[0].Location.S3Location.BucketName, input.job.Id));
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
using Amazon.CodePipeline;
using Newtonsoft.Json;
using System.IO;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace lambdaEmptyFunction
{
    public class Function
    {
        public class CodePipelineInput
        {
            [JsonProperty("CodePipeline.job")]
            public Amazon.CodePipeline.Model.Job job { get; set; }
        }

        public void FunctionHandler(CodePipelineInput input, ILambdaContext context)
        {
            context.Logger.LogLine(string.Format("data {0} {1} {2}", input.job.AccountId, input.job.Data.InputArtifacts[0].Location.S3Location.BucketName, input.job.Id));
        }
    }
}