dongqian9567 2018-06-26 07:26
浏览 390

挂在AWS Lambda上的数据库连接

I am trying to do basic db connection in AWS Lambda with Go, and for some reason, it got stuck at db.prepare() and no log is presented in cloudwatch.

func Handler(request Request) (Response, error) {

    db, err := sql.Open("mysql", dbUsername+":"+dbPassword+"@tcp("+dbURL+":"+dbPort+")/"+dbName)
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()
    stmt, err := db.Prepare("SELECT id, password FROM package_passwords WHERE password = ?")
    return Response{
        Message: "rows",
        Ok:      false,
    }, nil
}

weird thing is that the code above stuck at least more than 5 second in AWS Lambda while it works fine in plain go run/ go build.

  • 写回答

2条回答 默认 最新

  • dqyuipw44576 2018-06-27 00:44
    关注

    If it is a RDS operation, I think it is getting timeout. The default timeout of a lambda function is 6 seconds and therefore it is getting timeout before the operation finishes with RDS. To avoid this you do not have to increase the timeout. Instead of that you can make "callBackWaitsForEmptyEventLoop" false as your first line of code in lambda function.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器