首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用chalice部署时"Endpoint request timed out“

使用chalice部署时"Endpoint request timed out“
EN

Stack Overflow用户
提问于 2021-03-09 23:49:16
回答 1查看 138关注 0票数 0

此代码在使用'chalice local‘部署时运行良好,但当我使用'chalice deploy’部署它并向端点发送post请求时,我收到一个状态: 504网关超时和消息:"Endpoint request timeout“。

代码语言:javascript
复制
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
    }
EN

回答 1

Stack Overflow用户

发布于 2021-11-04 11:27:49

网关超时,因为lambda在30秒超时内没有响应。

这可能是与数据库连接的问题(ip阻塞或类似问题)。

  1. 从lambda中删除数据库的初始化并创建运行状况检查端点。

  1. 如果运行状况检查端点正常工作,您的数据库可能会静默放弃您的连接尝试。

  1. 从任何IP

打开数据库连接

更新代码:

代码语言:javascript
复制
   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}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66550196

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档