在AWS Elastic Beanstalk上部署Tornado应用程序 [英] Deploying Tornado app on AWS Elastic Beanstalk

查看:81
本文介绍了在AWS Elastic Beanstalk上部署Tornado应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Python 2.7/Tornado 编写的服务器,我正在尝试将其部署在AWS上. 我遇到了 AWS Elastic Beanstalk ,它看起来像是一种非常方便的代码部署方法.

I have a server written in Python 2.7/Tornado and I am trying to deploy it on AWS. I came across AWS Elastic Beanstalk which looked like a very convenient method to deploy my code.

我仔细阅读了教程并能够部署Flask示例应用程序. 但是,我不知道如何部署如下所示的龙卷风测试应用程序.

I went through this tutorial and was able to deploy the Flask sample app. However, I can't figure out how to deploy a test tornado app like below.

import tornado.web
import tornado.ioloop

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

if __name__ == "__main__":
    app = tornado.web.Application([
        (r"/.*", MainHandler),
    ])

    app.listen(5000)
    tornado.ioloop.IOLoop.current().start()

当我尝试部署上述应用程序时,我的所有请求都导致错误500,并且我不知道如何解决此问题,因为我不知道Flask示例如何工作,但Tornado代码却不起作用.

All my requests result in an Error 500 when I try to deploy the above application and I have no idea how to troubleshoot this problem as I have no idea how the Flask sample is working but the Tornado code is not.

requirements.txt 文件中包含tornado == 4.4.2的条目.

The requirements.txt file has an entry for tornado==4.4.2 in it.

我尝试添加一些日志语句以写入外部文件,但未创建该文件,这可能意味着该应用程序甚至无法启动.

I tried adding a few log statements to write to an external file but the file is not being created, which probably means the application does not even start.

如果有人可以提供一些在AWS-EB上部署Tornado应用程序的步骤,或者我应该如何开始对此进行故障排除,那将是很棒的. 请让我知道是否需要提供更多详细信息.

It would be great if someone can provide some steps on deploying a Tornado app on AWS-EB or how I should start troubleshooting this. Please let me know if I need to provide any more details.

谢谢!

在注意到httpd error_log文件,AWS文档和Berislav Lopac的答案中的错误之后,我找到了实施Tornado服务器的正确方法. 这是一个简单的服务器

After noticing the errors in httpd error_log file, AWS Documentation and Berislav Lopac's answer, I found the correct way to implement the Tornado server. Here is a simple server

import tornado.web
import tornado.wsgi
import tornado.ioloop

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

webApp = tornado.web.Application([
    (r"/", MainHandler),
])

# Wrapping the Tornado Application into a WSGI interface
# As per AWS EB requirements, the WSGI interface must be named
# 'application' only
application = tornado.wsgi.WSGIAdapter(webApp)

if __name__ == '__main__':
    # If testing the server locally, start on the specific port
    webApp.listen(8080)
    tornado.ioloop.IOLoop.current().start()

其他链接: Tornado WSGI文档

推荐答案

我相信您的问题与Elastic Beanstalk使用WSGI为Python Web应用程序提供服务而Tornado的服务器不符合WSGI的事实有关.您可能需要先通过 WSGI适配器将其包装,然后通过WSGI.

I believe your issue is related to the fact that Elastic Beanstalk uses WSGI for serving Python Web apps, while Tornado's server is not WSGI-compliant. You might want to try wrapping your app in the WSGI adapter before serving it via WSGI.

除非您依赖Tornado的异步功能,否则它应该可以正常工作,因为WSGI是严格同步的.

This should work fine unless you rely on Tornado's asynchronous capabilities, as WSGI is strictly synchronous.

这篇关于在AWS Elastic Beanstalk上部署Tornado应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆