簡體   English   中英

請求返回“端點請求超時”

[英]request returning "Endpoint request timed out"

我已經使用 zappa 在 aws lambda 上部署了一個 flask 應用程序,現在該應用程序在除我的主要端點之外的所有端點上運行良好,當我在其上發出發布請求時它返回 {“消息”:“端點請求超時”}

真的需要修復或想法如何克服這個我需要調用分析路線,部署的 url 是

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

嘗試增加我的應用程序超時限制無濟於事似乎 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()



如果您的請求是同步的,則嘗試在lambda的基本設置中增加內存。 對我有用(為您的功能分配的CPU與所配置的內存成比例)。

您可以使用多線程來減少響應時間。

此鏈接可能對您有幫助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

...有時您只需要一種簡單的方法即可在 function 前面配置 HTTPS 端點,而無需學習、配置和操作除 Lambda 之外的其他服務。

Lambda 基本上剝離了它自己的快遞服務器並直接與互聯網通信,而不會對通信施加 API 網關限制

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM