简体   繁体   English

如何使用弹性 beantalk 和 aws 修复 Flask 应用程序中的内部服务器错误

[英]How to fix internal server error in Flask application using elastic beanstalk and aws

When I run my flask application locally, I can connect to MySQL RDS just fine.当我在本地运行我的 Flask 应用程序时,我可以很好地连接到 MySQL RDS。 However, when I try to deploy the app using Elastic Beanstalk, I get a "500 Internal Server Error".但是,当我尝试使用 Elastic Beanstalk 部署应用程序时,出现“500 内部服务器错误”。 I do not know if this helps or not, but when I use a local sqlite file, my application works as intended both when ran locally and when deployed with Elastic Beanstalk.我不知道这是否有帮助,但是当我使用本地 sqlite 文件时,我的应用程序在本地运行和使用 Elastic Beanstalk 部署时都按预期工作。

I did try and work along with this page, but I did not notice any difference when I included the environment properties.我确实尝试过使用此页面,但是当我包含环境属性时,我没有注意到任何区别。 https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html#python-rds-create https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-rds.html#python-rds-create

Here is my __init__.py file.这是我的 __init__.py 文件。 I just comment out whichever database URI I do not wish to use when testing.我只是注释掉我在测试时不想使用的任何数据库 URI。

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager

application = Flask(__name__)
application.config['SECRET_KEY'] = 'c4633b5a978d282104dbc44c32c9486'
application.config['SQLALCHEMY_DATABASE_URI'] =  
'mysql+pymysql://<username>:<password>@garbagero.cuz5hqf0nh5m.us-east- 
2.rds.amazonaws.com/ebdb'
#application.config['SQLALCHEMY_DATABASE_URI'] =  'sqlite:///site.db'
db = SQLAlchemy(application)
bcrypt = Bcrypt(application)
login_manager = LoginManager(application)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'

from garbageRO import routes

EDIT: I finally figured out that I accidentally left 1 package out of my requirements.txt file.编辑:我终于发现我不小心从我的 requirements.txt 文件中遗漏了 1 个包。 I thought I had already double checked this before posting but apparently I did not.我以为我在发帖前已经仔细检查过了,但显然我没有。

I do recommend that you debug your application using the verbose mode of Flask and SQLAlchemy, so you can better know whats going on, with this level or detail i can only suggest something to check like the permissions/IAM on AWS, to check if your ElasticBeanstalk can really access the RDS, im assuming the ELB/applcation use a set of credentials, and you tested locally with another credentials, right?我确实建议您使用 Flask 和 SQLAlchemy 的详细模式调试您的应用程序,这样您就可以更好地了解发生了什么,有了这个级别或细节,我只能建议检查 AWS 上的权限/IAM,以检查您的ElasticBeanstalk 真的可以访问 RDS,我假设 ELB/应用程序使用一组凭据,并且您使用另一个凭据在本地进行了测试,对吗?

About the "verbose mode", try setting the SQLALCHEMY_ECHO to True: http://flask-sqlalchemy.pocoo.org/2.3/config/ There's also this option ive not tested: https://github.com/pallets/flask-sqlalchemy/pull/208/files?short_path=fd40cf2关于“详细模式”,尝试将 SQLALCHEMY_ECHO 设置为 True: http ://flask-sqlalchemy.pocoo.org/2.3/config/ 还有这个选项我没有测​​试过: https : //github.com/pallets/flask- sqlalchemy/pull/208/files?short_path=fd40cf2

And on the Flask app you can set debug to True also.在 Flask 应用程序上,您也可以将 debug 设置为 True。

Another option, is to debug if you can connect on the RDS directly with a client on the machine/container, or a least if a telnet is working.另一种选择是调试是否可以在 RDS 上直接与机器/容器上的客户端连接,或者至少在 telnet 工作时进行调试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 内部服务器错误:AWS Elastic Beanstalk上的Flask上的Dash - Internal Server Error: Dash on Flask on AWS Elastic Beanstalk 如何使用应用程序工厂将Flask应用程序部署到AWS Elastic beantalk - How to deploy Flask app to AWS Elastic beanstalk using an application factory 如何将烧瓶应用程序发送到 AWS Elastic Beanstalk? - How to send a flask application to AWS Elastic Beanstalk? 在 AWS Elastic Beanstalk 上部署 Django-Wagtail 应用程序时出现 500 内部服务器错误 - 500 internal server error deploying Django-Wagtail application on AWS Elastic Beanstalk 上传 Flask 应用程序时出现 AWS Elastic Beanstalk 错误 - AWS Elastic Beanstalk error when uploading Flask application 条带支付后 AWS Elastic Beanstalk 内部服务器错误 - AWS Elastic Beanstalk internal server error after stripe payment Django 内部服务器 500 错误 AWS Elastic-Beanstalk 问题 - Django Internal Server 500 Error AWS Elastic-Beanstalk issue Django 的 AWS Elastic Beanstalk 500 内部服务器错误 - AWS Elastic Beanstalk 500 Internal Server Error with Django Python Flask 服务器部署在 Elastic Beanstalk 上,出现 AWS 内部服务错误,日志显示 SECRET_KEY 从未设置? - Python Flask server deployed on Elastic Beanstalk with AWS Internal Service Error, Logs say SECRET_KEY was never set? 将 Django 应用程序部署到 Elastic Beanstalk 时出现内部服务器错误 500 - Internal Server Error 500 when deploying Django Application to Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM