簡體   English   中英

使用聖杯部署“端點請求超時”

[英]"Endpoint request timed out" with chalice deploy

此代碼在使用 'chalice local' 部署時工作正常,但是當我使用 'chalice deploy' 部署它並向端點發送發布請求時,我收到一個狀態:504 網關超時和消息:“端點請求超時”。

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
    }

網關超時,因為 lambda 在 30 秒超時內沒有響應。

這可能是與數據庫連接的問題(ip 被阻止或類似)。

  1. 從 lambda 中刪除數據庫的啟動並創建健康檢查端點。

  2. 如果運行狀況檢查端點有效,您的數據庫可能會默默地放棄您的連接嘗試。

  3. 從任何 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}

暫無
暫無

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

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