在AWS beanstalk上执行的C ++ Hello world

时间:2017-03-22 14:51:56

标签: python c++ amazon-web-services amazon-ec2 elastic-beanstalk

我在AWS Elastic Beanstalk实例上创建了一个基于Python的Web应用程序。现在我想从Python应用程序执行一个简单的C ++可执行文件(例如application.py) 我能够使用build-essential和g ++,make等预先配置实例。 但是,当我通过python应用程序调用我的Hello world应用程序时,我收到内部服务器错误。

事实上,我正在寻找在AWS beanstalk上运行C ++应用程序的解决方案。我的尝试包括:

  1. 使用Makefile通过从application.py调用make命令然后运行它来构建c ++文件。 (没有成功)

  2. 构建可执行文件并将其复制到AWS EB然后运行它。 (没有成功)

  3. 创建一个FastCGI应用程序来做同样的事情。但我不知道如何在AWS EB实例上部署它。

  4. 我知道C ++不属于AWS EB支持的语言列表。但是应该有一种在云上部署C ++可执行文件的方法。

    所以,我很感激任何帮助或建议。

    修改 以下是application.py的代码:

    from flask import Flask
    import subprocess as sp
    
    def say_hello(username = "Hamid"):
    
        ll = []
    
        proc = sp.Popen(['make'], stdout=sp.PIPE, stderr=sp.PIPE, bufsize=1)
        with proc.stdout:
            for line in proc.stdout:
                ll.append(line)  
    
        proc.wait()
    
        proc = sp.Popen(['./helloworld'], stdout=sp.PIPE, stderr=sp.PIPE, bufsize=1)
        with proc.stdout:
            for line in proc.stdout:
                ll.append(line)    
    
        proc.wait()
    
        str_out = ""
        for l in ll:
            str_out += str(l) + "  "
        return '<p>Application output is: %s !</p>\n' % str_out
    
    # some bits of text for the page.
    header_text = '''
        <html>\n<head> <title>EB Flask Test</title> </head>\n<body>'''
    instructions = '''
        <p><em>Hint</em>: This is a RESTful web service! Append a username
        to the URL (for example: <code>/Thelonious</code>) to say hello to
        someone specific.</p>\n'''
    home_link = '<p><a href="/">Back</a></p>\n'
    footer_text = '</body>\n</html>'
    
    # EB looks for an 'application' callable by default.
    application = Flask(__name__)
    
    # add a rule for the index page.
    application.add_url_rule('/', 'index', (lambda: header_text +
        say_hello() + instructions + footer_text))
    
    # add a rule when the page is accessed with a name appended to the site
    # URL.
    application.add_url_rule('/<username>', 'hello', (lambda username:
        header_text + say_hello(username) + home_link + footer_text))
    
    # run the app.
    if __name__ == "__main__":
        # Setting debug to True enables debug output. This line should be
        # removed before deploying a production app.
        application.debug = True
        application.run()
    

0 个答案:

没有答案
相关问题