You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Python Bottle服务器时如何通过AWS App Runner健康检查?

问题描述

我DevOps经验不足,现有一个基于Python Bottle框架的小型项目,本地运行正常,但尝试通过AWS App Runner部署时,始终无法通过8080端口的健康检查,服务自动回滚。以下是部署日志及核心代码,请求解决方法:

部署日志
11-05-2022 02:37:47 PM [AppRunner] Health check on port '8080' failed. Service is rolling back. Check your configured port number. For more information, read the application logs.
11-05-2022 02:31:36 PM [AppRunner] Performing health check on port '8080'.
11-05-2022 02:31:26 PM [AppRunner] Provisioning instances and deploying image for publicly accessible service.
11-05-2022 02:31:15 PM [AppRunner] Successfully built source code.
11-05-2022 02:26:53 PM [AppRunner] Starting source code build.
11-05-2022 02:26:52 PM [AppRunner] Successfully pulled source code.
11-05-2022 02:25:56 PM [AppRunner] Service status is set to OPERATION_IN_PROGRESS.
11-05-2022 02:25:55 PM [AppRunner] Service creation started.
核心代码(server.py)
import os
from bottle import route, run, template, get, post, request
from scraper import scrap, get_dropdown_choices

index_html = '''My first web app! By <strong>{{ author }}</strong>.'''

@route('/')
def index():
    return template(index_html, author='Tim')

@route('/name/<name>')
def name(name):
    return template(index_html, author=name)

run(host='0.0.0.0', port=8080)
解决方法
  • 检查健康检查配置:登录AWS App Runner控制台,确认健康检查的路径为/、HTTP方法为GET、预期状态码包含200。默认配置通常是/,但如果被修改过会导致检查失败。
  • 查看应用运行日志:在App Runner控制台的服务详情页找到“日志”选项,查看应用的标准输出/错误日志,确认服务是否成功启动。常见问题包括依赖缺失(如scraper模块未正确安装)、代码报错导致服务终止。
  • 适配环境变量端口:修改代码中的端口配置,优先读取环境变量PORT(App Runner可能会动态分配端口),修改后的启动代码如下:
    run(host='0.0.0.0', port=int(os.getenv('PORT', 8080)))
    
  • 确认启动命令正确性:检查App Runner的启动命令是否为python server.py,如果项目使用虚拟环境或依赖文件(如requirements.txt),需确保启动前已安装所有依赖,例如将启动命令设置为:
    pip install -r requirements.txt && python server.py
    
  • 验证依赖完整性:确保requirements.txt文件包含所有必要依赖(至少包含bottle),避免部署时因缺失依赖导致服务无法启动。

内容的提问来源于stack exchange,提问作者LLaP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 13:41:42