【问题标题】:AWS Lambda C# - Fail to query SQL with DapperAWS Lambda C# - 无法使用 Dapper 查询 SQL
【发布时间】:2018-03-06 19:43:49
【问题描述】:

我创建了一个在本地模式下完美运行的 aws 函数,但是在 aws lambda 中执行时,我得到了:

进程在完成请求之前退出

该函数使用 Dapper 连接到 RDS SQL 连接。我检查了安全组,入站/出站规则是正确的。

LambdaLogger.Log($"Listando doacao em visita");

        using (SqlConnection conexao = new SqlConnection(_connectionString))
        {
            LambdaLogger.Log($"Conexao aberta");

            var weekDay = (int)DateTime.Now.DayOfWeek;
            var stringSql = $@"{_query}
                    WHERE
                    p.status = {(int)StatusPedido.DoacaoEmVisita} and
                    p.datainclusao <= Getdate() - 7
                ";

            LambdaLogger.Log($"Query gerada");


            //the function exited on this line
            var query = conexao.Query<AlertaDisponibilidadeERetiradaDTO, EnderecoDTO, AlertaDisponibilidadeERetiradaDTO>(
                stringSql
                , (pedido, endereco) =>
                {
                    pedido.Endereco = endereco;
                    return pedido;
                }, splitOn: "IdEndereco");

            LambdaLogger.Log($"Query executada.");

            return query;
        }

我已经用 try/catch 包装了代码,以记录异常发生的原因,但不幸的是,该函数立即存在,我不知道为什么。

【问题讨论】:

    标签: c# amazon-web-services lambda aws-lambda


    【解决方案1】:

    在完成请求之前进程退出

    表示您的 Lambda 异常。检查 AWS Cloudwatch 以了解处理并记录到 cloudwatch 的异常。

    如果您没有看到任何日志记录,则您的依赖项可能会失败。

    希望对你有帮助。

    【讨论】:

    • CloudWatch 刚刚记录了“LambdaLoger.Log”,我用 try catch 包装了代码,但没有被捕获。我没有任何日志可以查看发生了什么
    【解决方案2】:

    我通过根据 .NET Standars 1.6.1 => 1.6.0 降级所有软件包解决了我的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-26
      • 2019-03-15
      • 2020-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多