如何在AWS上设置python开发环境?

您需要安装Python,pip,virtualenv,awswebcli和SSH客户端才能在AWS上设置Python开发环境。您可以按照http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html上的说明进行安装。

一旦安装了所有这些软件包,就需要设置一个虚拟环境,以免全局软件包受到污染。使用以下命令来设置虚拟环境:

$ virtualenv -p python2.7 /tmp/hello-world
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /tmp/hello-world/bin/python2.7
Also creating executable in /tmp/hello-world/bin/python
Installing setuptools, pip...done.

准备好虚拟环境后,通过运行环境的bin目录中的激活脚本来启动它。例如,要启动在上一步中创建的hello-world环境,请输入:

$ . /tmp/hello-world/bin/activate

创建虚拟环境后,您可以随时通过再次运行其激活脚本来重新启动虚拟环境。

要配置Python应用程序以进行部署,请从您的virtualenv内部,返回到项目目录树的顶部,并创建一个requirements.txt文件,其中包含应用程序的需求(您要导入的第三方模块)及其版本号(如果没有,您需要最新的)。例如,

Flask==0.8
Jinja2==2.6
Werkzeug==0.8.3
certifi==0.0.8
chardet==1.0.1 :
...

或者,您可以使用pip使用以下命令将计算机上所有已安装的软件包下载到requirements.txt文件:

$ pip freeze >requirements.txt

这样,AWS可以使用与开发和测试应用程序相同的程序包和相同的版本来复制应用程序的Python环境。

现在,使用“ eb init”命令配置AWS EB CLI存储库。

$ eb init -p python2.7 hello-world

应用程序hello-world已创建。

此命令将创建一个名为hello-world的新应用程序,并将您的本地存储库配置为使用最新的Python 2.7平台配置创建环境。再次运行eb init以配置默认键对,以便您可以使用SSH连接到运行您的应用程序的EC2实例

$ eb init
Do you want to set up SSH for your instances?
(y/n): y
Select a keypair.
1) my-keypair
2) [ Create new KeyPair ]

如果已经有一对,请选择一个键对,或者按照提示创建一个新的键对。如果没有看到提示或以后需要更改设置,请运行eb init -i。创建一个环境,然后使用eb create将您的应用程序部署到该环境:

$ eb create hello-env

此命令将创建一个名为hello-env的负载平衡Elastic Beanstalk环境。

如果您遇到任何问题,可以在此处查看更详细的文档:http : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-configure-for- eb