调用 PostText 操作时:无效的机器人配置:Lambda 请求未在允许的时间30 秒内完成

问题描述

在 lambda 中使用 Python + Lex bot + lexclient post_text 在后端。

在 lambda 函数调用 post API 时出现此错误

An error occurred (DependencyFailedException) when calling the PostText operation: Invalid Bot Configuration: Lambda request did not complete within permissible time (30 seconds).

在对话结束时,我调用一个 post API 以使用收集到的后端响应来更新数据库。在调用这个 requests.post 之后,request 需要一些时间 POST 并在此之前获得响应,30 秒后 lambda 超时并且 lex 客户端抛出 DependencyFailedException 错误,说在允许的时间内没有从 lambda 获得响应。因此,我将 lambda 超时设置增加到 15 分钟。现在,我在云监视中 30 秒后收到发布 API 响应,它成功更新数据库并获得成功响应,但仍然,lex-runtime 客户端提供相同的 DependencyFailedException 并且不返回履行消息(最终感谢消息)。

这是因为 post API 需要 30 秒的时间来命中 API。当我通过邮递员点击相同的 API 时,它会在一秒钟内响应。因此,我编写了一个测试 lambda 函数来仅访问此 API 并查看响应时间。 test_api_call.py

import requests
import os,time
def lambda_handler(event=None,context=None):
    """
    Route the incoming request based on intent.
    The JSON body of the request is provided in the event slot.
    """
    # By default,treat the user request as coming from the America/New_York time zone.
    os.environ['TZ'] = 'America/New_York'
    time.tzset()
    candidate_resp = {
            "candidate_id":"1","status":"Success",}

    api_url = "https://my-back-end/response_update"

    res = requests.post(api_url,data=candidate_resp)
    print(res.text)

测试 lambda 函数在几秒钟内给出响应。

START RequestId: 7f43d3e9-3f09-48c5-b953-375f2999fec0 Version: $LATEST
{
  "msg": "success"
}
END RequestId: 7f43d3e9-3f09-48c5-b953-375f2999fec0
REPORT RequestId: 7f43d3e9-3f09-48c5-b953-375f2999fec0  Duration: 223.83 ms Billed Duration: 224 ms Memory Size: 128 MB Max Memory Used: 65 MB  Init Duration: 450.99 ms

我想知道为什么在我的 bot lambda 函数 post API 需要 30 秒才能响应,而 lex 客户端因 DependencyFailedException 而失败。

Lex 机器人会话超时:10 分钟(您的机器人应保留上下文多长时间)。

感谢您在此问题上的帮助。 TIA。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)