在 C# 中使用 DynamoDBEvents 调试 AWS 无服务器 Lambda 函数

Debugging AWS Serverless Lambda Functions with DynamoDBEvents in C#

我正在开发一个 AWS 无服务器应用程序,其中包含一些从 DynamoDB 触发器触发的 Lambda 函数...

基本上,当在 DynamoDB table 中输入一条新记录时...它会触发一个 LamdaFunction,它会在 DynamoDBEvent 参数中读取新记录的参数,然后执行一些业务逻辑并将数据写入另一个 DynamoDBEvents 参数。

我如何调试才能看到如何从 DynamoDBEvents 参数中获取值?或者我可以使用什么策略来实现我想要做的事情?

有没有办法将 VisualStudio 测试项目中的 DynamoDBEvent 模拟到我在本地的所有函数?

public APIGatewayProxyResponse AddUserTask(DynamoDBEvent dynamoEvent, ILambdaContext context)
{
    foreach (var record in dynamoEvent.Records)
    {
        //do stuff with the values from the new record in the dynamoEvent parameter...
    }

    var returnObj = new { Success = true };
    var response = new APIGatewayProxyResponse
    {
        StatusCode = (int)HttpStatusCode.OK,
        Body = SerializeObject(returnObj),
        Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
    };

    return response;
}

据我所知,使用 AWS Lambda 进行调试的主要方式是将调试输出日志记录到 CloudWatch。 AWS 提供了 C# Logging documentation.

context.Logger.Log("My debug log!");

您可以尝试将您的记录传递给它。

context.Logger.Log(var.EventSourceArn);

可能会打印出一些东西,否则请查看文档以了解还有哪些内容可用。