我已经使用zappa在aws lambda上部署了flask应用程序,现在该应用程序在除我的主端点外的所有端点上都运行良好,当我对其发出发布请求时它返回 { “ message”:“端点请求超时” }
真的需要解决方法或想法,我需要调用分析路由,已部署的网址是
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()
答案 0 :(得分:0)
如果您的请求是同步的,则尝试在lambda的基本设置中增加内存。对我有用(为您的功能分配的CPU与所配置的内存成比例)。