2018-05-22 09:29
浏览 50

AWS Lambda GoLang错误

Is it OK to panic() when failed to create AWS session? As an opposite, I can just return the error from my handler function (in this case I have to create the session in the handler code, but not in the init()).

The docs say

Lambda will re-create the function automatically

Does it mean the panic always causes the cold-start and is preferred to return error from the handler?

图片转代码服务由CSDN问答提供 功能建议

创建AWS会话失败时, panic()是否可以? 相反,我可以从处理程序函数中返回错误(在这种情况下,我必须在处理程序代码中创建会话,但不能在 init()中创建会话)。 \ n




  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongzhui9936 2018-05-29 19:48

    The answer depends on what is going on in init section.

    If you create session clients to connect to other services it might be good to panic and cause cold-start than continue container's lifecycle with the failed clients.

    解决 无用
    打赏 举报
  • duanbin198788 2018-05-22 10:34

    Yes. A panic will trigger a cold restart of your code. The use of panic should be reserved for exceptional circumstances; returning an error is to be preferred in most circumstances.

    解决 无用
    打赏 举报

相关推荐 更多相似问题