在 Elastic Beanstalk 上部署 Pyramid 应用程序

Deploy Pyramid Application on Elastic Beanstalk

有没有人有通过 Elastic Beanstalk 安装 Pyramid 应用程序的经验?我的应用程序已部署,但我无法将应用程序的 application.py(或 pyramid.wsgi)文件配置为正常工作。在 get_app 内发生以下错误:

File "/opt/python/run/venv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 829, in resolve
[Sun Jul 17 21:24:15.482379 2016] [:error] [pid 736] [remote 127.0.0.1:9522]     raise DistributionNotFound(req, requirers)
[Sun Jul 17 21:24:15.482427 2016] [:error] [pid 736] [remote 127.0.0.1:9522] DistributionNotFound: The 'MyApp' distribution was not found and is required by the application

其中 MyApp 是我要 运行 的应用程序。

这是我的 application.py:

from pyramid.paster import get_app, setup_logging
import os, site, sys
ini_path = os.path.join(os.path.dirname(__file__), 'production.ini')
setup_logging(ini_path)
application = get_app(ini_path, 'main')

似乎错误发生是因为它在 /opt/python/run/venv/lib/python2.7/site-packages/ 而不是 /opt/current/python/app/ 中寻找 MyApp。我错过了什么?我需要在我的路径中添加一些东西吗?

感谢 "pylons-discuss" Google 群组论坛上的一位朋友,我现在有了一个有效的解决方案。

您需要为您的环境添加一个配置命令,运行是 setup.py develop 命令。为此,您需要将文件添加到名为 packages.config 的 .ebextensions 文件夹(或使用您喜欢的任何命名方案),内容如下:

container_commands:
  01_setup:
    command: "/opt/python/run/venv/bin/python setup.py develop"

或者,您可以(并且可能应该)运行:

container_commands:
  01_setup:
    command: "/opt/python/run/venv/bin/pip install -e ."

(虽然我希望有人验证这一点,只是为了确定。)

接下来,运行 eb deploy 命令。 Elastic Beanstalk 现在应该可以识别您的包已安装。干杯!

要了解前两个解决方案之间的区别,请参阅:

Python setup.py develop vs install