【问题标题】:Debugging AWS Serverless Lambda Functions with DynamoDBEvents in C#在 C# 中使用 DynamoDBEvents 调试 AWS 无服务器 Lambda 函数
【发布时间】:2018-01-21 22:40:26
【问题描述】:

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

基本上当在 DynamoDB 表中输入新记录时...它会触发 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;
}

【问题讨论】:

    标签: c# amazon-web-services amazon-dynamodb aws-lambda visual-studio-debugging


    【解决方案1】:

    我知道使用 AWS Lambda 进行调试的主要方法是使用调试输出日志记录到 CloudWatch。 AWS 提供了C# Logging documentation

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

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

    context.Logger.Log(var.EventSourceArn);
    

    可能会打印一些内容,否则请查看文档以了解其他可用内容。

    【讨论】:

      猜你喜欢
      • 2019-01-21
      • 2020-03-09
      • 2019-02-24
      • 2019-04-17
      • 2021-01-07
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多