Python in AWS Elastic Beanstalk: Private package dependencies

Question:

I would like to deploy a Python Flask application on beanstalk.

The application depends on external packages (e.g. geopy) and internal packages (e.g. adam_geography).

The manual

Create a requirements.txt file and place it in the top-level directory
of your source bundle.

This would probably fetch geopy and its dependencies, but would not fetch adam_geography which is available from a custom repo inside my VPC.

How do I specify/upload private, internal Python package dependencies in a Beanstalk application?

Asked By: Adam Matan

||

Answers:

1) copy internal Python package to server

2) use Pip’s “editable installs” feature to install the private package:

pip install -e path/to/SomeProject

http://pip.readthedocs.org/en/latest/reference/pip_install.html#editable-installs

Answered By: johntellsall

Use ebextensions to specify custom commands you can use to download files on all your EC2 instances. These ebextensions can be used to run pip like @shavenwarthog suggested in his answer.
Create a directory called .ebextensions in your app source root directory. Inside this directory create a file with a .config extension say 01-custom-files.config.
This file can contain custom unix commands you want to run on each EC2 instance.
You can run your own scripts here.

You can also use container_commands which are executed after unzipping your app source on the EC2 instance.

Read more about commands and container_commands here. You can also find examples here:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands

Answered By: Rohit Banga