此代码在使用'chalice local‘部署时运行良好,但当我使用'chalice deploy’部署它并向端点发送post请求时,我收到一个状态: 504网关超时和消息:"Endpoint request timeout“。
from chalice import Chalice
from sqlalchemy import create_engine
app = Chalice(app_name='demo')
app.debug = True
engine = create_engine('postgresql://postgres:postgres@DATABASE_URI:5432/playground')
@app.route('/', methods=['POST'])
def index():
req_data = app.current_request.to_dict()
query_params = req_data['query_params']
name = str(query_params['name'])
age = int(query_params['age'])
with engine.connect() as conn:
conn.execute("INSERT INTO demo VALUES (%s, %s);", (name, age))
return {
'message': 'successfully inserted data with:',
'name': name,
'age': age
}发布于 2021-11-04 11:27:49
网关超时,因为lambda在30秒超时内没有响应。
这可能是与数据库连接的问题(ip阻塞或类似问题)。
打开数据库连接
更新代码:
from chalice import Chalice
from sqlalchemy import create_engine
app = Chalice(app_name='demo')
app.debug = True
@app.route('/', methods=['POST'])
def index():
engine = create_engine('postgresql://postgres:postgres@DATABASE_URI:5432/playground')
req_data = app.current_request.to_dict()
query_params = req_data['query_params']
name = str(query_params['name'])
age = int(query_params['age'])
with engine.connect() as conn:
conn.execute("INSERT INTO demo VALUES (%s, %s);", (name, age))
return {
'message': 'successfully inserted data with:',
'name': name,
'age': age
}
@app.route('/healthcheck', methods=['POST'])
def index():
return {"success": True}https://stackoverflow.com/questions/66550196
复制相似问题