Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

python - when calling the PostText operation: Invalid Bot Configuration: Lambda request did not complete within permissible time (30 seconds)

Using Python in lambda + Lex bot + lexclient post_text in back end.

I am getting this error when I call post API in my lambda function.

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

At the end of the conversation, I am calling one post API to update DB with the collected response to the backend. After calling this requests.post, request takes some time POST and get response before that, lambda timeout after 30 seconds and lex client throwing DependencyFailedException error by saying did not get a response from lambda within permissible time. So, I have increased the lambda time out settings to 15 mins. Now, I am getting post API response after 30 seconds in cloud watch, It successfully updated DB and get success response back, but still, lex-runtime client gives same DependencyFailedException and not returning fulfillment message(Final Thank you message).

It's because post API takes 30 seconds time to hit API. when I hitting the same API via postman, its responds within a second. So, I wrote one test lambda function to only hit this API and see the response time. 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)

test lambda function gives responds back within seconds.

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

I wonder why in my bot lambda function post API takes exactly 30 seconds to respond whereas lex client failed with DependencyFailedException.

Lex bot session timeout: 10 mins(How long your bot should retain context).

Appreciate your help on this issue. TIA.

question from:https://stackoverflow.com/questions/65893075/when-calling-the-posttext-operation-invalid-bot-configuration-lambda-request-d

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...