How to set up your python development environment on AWS?

PythonServer Side ProgrammingProgrammingAWS

You need to have Python, pip, virtualenv, awswebcli and a SSH client installed to set up your Python Development Environment on AWS. You can follow instructions at to install these.

Once you have all those installed, you need to set up a virtual environment so that your global packages do not get polluted. Use the following command to set up a 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...done.

Once your virtual environment is ready, start it by running the activate script located in the environment's bin directory. For example, to start the hello-world environment created in the previous step, you would type:

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

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

To configure a Python application for deployment, from within your virtualenv, return to the top of your project's directory tree and create a requirements.txt file that contains your app's requirements(third party modules you are importing) with their version numbers(or without if you need latest one). For example,

chardet==1.0.1 :

Alternatively you can use pip to get all installed packages from your machine to the requirements.txt file using:

$ pip freeze >requirements.txt

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

Now configure AWS EB CLI repository with the 'eb init' command.

$ eb init -p python2.7 hello-world

Application hello-world has been created.

This command creates a new application named hello-world and configures your local repository to create environments with the latest Python 2.7 platform configuration. Run eb init again to configure a default keypair so that you can connect to the EC2 instance running your application with SSH

$ 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 key pair if you have one already, or follow the prompts to create a new one. If you don't see the prompt or need to change your settings later, run eb init -i. Create an environment and deploy you application to it with eb create:

$ eb create hello-env

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

If you face any issues, you can check more detailed documentation here:

Updated on 01-Oct-2019 06:45:55