如何调试ElasticBeanstalk错误" X%的请求失败了HTTP 5xx"

时间:2015-11-01 22:12:27

标签: ruby-on-rails amazon-web-services logging elastic-beanstalk

我的问题与AWS: None of the Instances are sending data类似,但错误消息略有不同。

我在ElasticBeanstalk上运行了一个Rails应用程序,它似乎正在正常运行。 Enhanced Health Monitoring会定期向我发送错误消息,例如:

  

环境健康已从Ok转变为Degraded。 20.0%的   请求因HTTP 5xx而失败。

百分比变化达到100%。即使我没有做出任何改变,一分钟后我收到一条后续消息,告诉我一切都恢复正常:

  

环境健康已从Degraded转为Ok。

我已经从ElasticBeanstalk下载了完整的日志,但我并不确切知道在哪里查看(各种目录中有大约20个不同的日志文件)。

我目前正在使用具有最小数据库,服务器等实例的免费AWS层。这可能是原因吗?我应该查看哪些日志文件,以及我应该寻找什么?

3 个答案:

答案 0 :(得分:5)

我在Elastic Beanstalk上运行rails应用程序,并发现将Beanstalk视为运行rails应用程序和Web服务器(Passenger或Puma)的计算机(在本例中为Amazon EC2实例)很有帮助。当您收到500错误时,可能是因为您的rails应用程序没有正确部署 - 在这种情况下,Passenger或Puma会返回错误 - 或者您的应用程序已正确部署但遇到错误,就像在本地机。

在任何一种情况下,要诊断错误,请从AWS控制台下载完整日志(打开正确的应用程序环境,然后选择日志>请求日志>完整日志>下载)。部署错误很难诊断,但我建议首先查看var-XX/logs/log/eb-activity.log。我怀疑您的错误来自您的rails应用程序本身,在这种情况下,我建议您查看var-XX/app/support/logs/passenger.logproduction.log。要查找500错误,请搜索" 500内部"然后像处理任何其他rails错误一样处理错误。

答案 1 :(得分:2)

您可以转到EC2实例并运行应用程序,就像在本地计算机上运行并查看日志一样。

您可以使用命令ssh eb ssh进入EC2实例,然后转到/opt/python/目录(对于Ruby或其他编程语言,这将有所不同)。

/opt/python/run是您将在其中找到从EC2实例运行的应用程序版本的目录。在venv目录中查找目录apprun

注意:上面的文件夹结构适用于Python,但是对于其他任何编程语言,在部署后都可以找到类似的文件夹结构。只需为您的编程语言寻找部署环境的标准目录结构即可。

对于Python:

/opt/python: Root of where you application will end up.
/opt/python/current/app: The current application that is hosted in the environment.
/opt/python/on-deck/app: The app is initially put in on-deck and then, after all the deployment is complete, it will be moved to current. If you are getting failures in your container_commands, check out out the on-deck folder and not the current folder.
/opt/python/current/env: All the env variables that eb will set up for you. If you are trying to reproduce an error, you may first need to source /opt/python/current/env to get things set up as they would be when eb deploy is running.
/opt/python/run/venv: The virtual env used by your application; you will also need to run source /opt/python/run/venv/bin/activate if you are trying to reproduce an error.

答案 2 :(得分:0)

我知道它有点晚但我想评论我用来查找错误的技巧,我用来通过ssh连接然后,一旦在应用程序中我尝试进入“rails console”它用来失败,但它通常显示您正在犯的错误。这个小技巧多次挽救了我的生命。希望它有所帮助!