How do I set up a Python development environment on AWS?

Python Methods and Functions

You need to install Python, pip, virtualenv, awswebcli, and an SSH client to set up your Python development environment on AWS. You can follow the instructions at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html to install them.

After you've installed all of these, you need to set up your virtual environment so that your global packages are not polluted. Use the following command to set up your virtual environment:

 $ 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 ... d one. 

When your virtual environment is ready, start it by running the activation script located in the bin directory of the environment. For example, to start the hello-world environment created in the previous step, enter:



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

Once created, you can restart the virtual environment at any time by running the activation script again.

To configure your Python application for deployment, from within your virtualenv go back to the top of your project directory tree and create a require.txt file that contains your application's requirements (imported third-party modules) with their version numbers (or without, you need the latter). For example,

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

Alternatively, you can use pip to transfer all installed packages from your computer to the needs.txt file using:

 $ pip freeze & gt; requirements.txt 

This allows AWS to replicate your application's Python environment using the same packages and versions you used to develop and test your application.



Now set up AWS EB CLI storage using & # 8216; eb init & # 8217 ;.

 $ eb init -p python2.7 hello-world 

The hello-world application has been created.

This command creates a new an app named hello-world and configures your local repository to create environments with the latest Py platform configuration thon 2.7. Run eb init again to set up the default key pair so you can connect to the EC2 instance running the SSH application.

 $ 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] 

Select a keypair if you already have one, or follow the instructions to create a new one. If you don't see the prompt or need to change the settings later, run eb init -i. Create an environment and deploy your application to it using eb create:

 $ eb create hello-env 

This command creates a load balanced Elastic Beanstalk environment named hello-env.

If you have any problems, you can check out more detailed documentation here: http://docs.aws.amazon.com/elasticbeanstalk/ latest / dg / create-deploy-python-django.html # python-django-configure-for







Get Solution for free from DataCamp guru