简体   繁体   English

请求返回“端点请求超时”

[英]request returning "Endpoint request timed out"

I have deployed a flask app on aws lambda using zappa now the app is running fine on all end points except my main one when i give post request on it it returns { "message": "Endpoint request timed out" }我已经使用 zappa 在 aws lambda 上部署了一个 flask 应用程序,现在该应用程序在除我的主要端点之外的所有端点上运行良好,当我在其上发出发布请求时它返回 {“消息”:“端点请求超时”}

really need a fix or idea how to over come this i need to call the analysis route, the deployed url is真的需要修复或想法如何克服这个我需要调用分析路线,部署的 url 是

https://2ixfyfcsik.execute-api.eu-west-2.amazonaws.com/dev https://2ixfyfcsik.execute-api.eu-west-2.amazonaws.com/dev

tried increasing my app timeout limit none avail it seems api gateway has 30 second time out so how to by pass that or not how to make my app return results in 30 seconds any help appreciated尝试增加我的应用程序超时限制无济于事似乎 api 网关有 30 秒超时所以如何绕过或不通过如何使我的应用程序在 30 秒内返回结果任何帮助表示赞赏

from flask import Flask, redirect, url_for, request, jsonify
from flask_cors import CORS
import os,json
from hatesonar import Sonar
from profanityfilter import ProfanityFilter


app = Flask(__name__)
CORS(app)



@app.route('/',methods = ['GET'])
def index():
    return jsonify({"message": "Hello World!"})



@app.route('/test',methods = ['GET'])
def test():
    results=[]
    post="Every Day. Narrated by Patch."
    sonar = Sonar()
    offensiveLanguage = sonar.ping(text=post)
    for item in offensiveLanguage['classes']:
        if (item['class_name']=='hate_speech'):
            if(item['confidence']>=0.9):
                hatesonar_hatespeech=item['coinfidence']
            else:
                hatesonar_hatespeech=0
            results.append(hatesonar_hatespeech)
        else:
            pass
        if (item['class_name']=='offensive_language'):
            if(item['confidence']>=0.9):
                hatesonar_swearing=item['coinfidence']
            else:
                hatesonar_swearing=0
            results.append(hatesonar_swearing)
    return jsonify(results)




@app.route('/offensiveLanguage',methods = ['POST', 'GET'])
def login():
   if request.method == 'POST':
      user = request.form['nm']
      return redirect(url_for('success',name = user))
   else:
      sonar = Sonar()
      text = request.args.get('text')
      print("text", text)
      offensiveLanguage = sonar.ping(text=text)
      print("offensiveLanguage", offensiveLanguage)
      return jsonify(offensiveLanguage)


@app.route('/analysis',methods = ['GET','POST'])
def profanity():
    if request.method == 'POST':
        profanitycount=0
        data = request.get_json()
        posts=[]
        for item in data:
            if ('media' in item):
                for x in item['media']:
                    if(x['mediaType']=='post'):
                        if (x['content']):
                            posts.append(x['content'])
                        else:
                            pass
                    else:
                        pass
            else:
                pass
        flat_list = []
        for sublist in posts:
            for item in sublist:
                flat_list.append(item)          
        for post in flat_list:
            pf = ProfanityFilter()
            swearing = pf.is_profane(post)
            if(swearing=='true'):
                profanitycount = profanitycount + 1
            else:
                profanitycount = profanitycount
            sonar = Sonar()
            offensiveLanguage = sonar.ping(text=post)   
    print("profanity", profanitycount)
    return jsonify(profanitycount)


if __name__ == '__main__':
        app.run()



if your request is sync then try to increase memory in Basic Setting of lambda. 如果您的请求是同步的,则尝试在lambda的基本设置中增加内存。 It was worked for me (Your function is allocated CPU proportional to the memory configured). 对我有用(为您的功能分配的CPU与所配置的内存成比例)。

You can use multi-threading to decrease the response time.您可以使用多线程来减少响应时间。

This link may be helpful for you AWS Lambda And Multi Threading Using Python此链接可能对您有帮助AWS Lambda 和多线程使用 Python

Mid-2022 there is now an official solution that bypasses the API Gateway and hence the annoying 29 second limit: AWS Lambda Function URLs: Built-in HTTPS Endpoints for Single-Function Microservices Mid-2022 there is now an official solution that bypasses the API Gateway and hence the annoying 29 second limit: AWS Lambda Function URLs: Built-in HTTPS Endpoints for Single-Function Microservices

... sometimes all you need is a simple way to configure an HTTPS endpoint in front of your function without having to learn, configure, and operate additional services besides Lambda. ...有时您只需要一种简单的方法即可在 function 前面配置 HTTPS 端点,而无需学习、配置和操作除 Lambda 之外的其他服务。

The Lambda basically spins off it's own express server and communicates directly with the internet, without imposing API Gateway limits on the communication Lambda 基本上剥离了它自己的快递服务器并直接与互联网通信,而不会对通信施加 API 网关限制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM