Search code examples
postgresqlamazon-web-servicespostgisamazon-elastic-beanstalkgeodjango

Configuring Amazon Elastic Beanstalk with PostGIS


Does anyone have any experience setting up Amazon Elastic Beanstalk with PostGIS (so that I can take advantage of Geodjango)?

There are a number of features that the default setup (RDS, featuring MySQL) does not currently support out of box: 1. PostgreSQL + PostGIS 2. The ability to install C/C++ libraries such as GEOS and Proj.4

Thanks in advance


Solution

  • If you want to use geodjango with Amazon Elastic Beanstalk you need to create a custom AMI where you can install PostGIS and then point your Elastic Beanstalk Application to that AMI when spinning up.

    Here is a good tutorial on how to customize an EBS AMI. There is also an AWS tutorial for that but I found the first one easier to understand. On my custom AMI I installed geos, gdal, proj4 and postgis from source, and postgres using yum install postgres. Below are the commands i used to install all libraries into the AMI.

    For the django app to find the libraries, I also set an additional environmental variable in the AWS EBS Console. In the menubar of my environment, I went to configuration --> software configuration and edited the Environment Properties by adding the property LD_LIBRARY_PATH set as /usr/local/lib/:$LD_LIBRARY_PATH.

    Since the beanstalk app instances are not forseen to run the database themselves, I also set up a Amazon RDS Postgres hosted database which is a relatively new service, it supports PostGIS.

    If you put that all together, you should get a very scaleable GeoDjango app!

    sudo yum install postgresql postgresql-devel postgresql-server postgresql9-contrib gcc gcc-c++ make libtool curl libxml2 libxml2-devel python-devel
    
    wget http://download.osgeo.org/proj/proj-4.8.0.zip
    unzip proj-4.8.0.zip
    cd proj-4.8.0
    ./configure
    make
    sudo make install
    cd ..
    
    wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
    tar -xvf geos-3.4.2.tar.bz2
    cd geos-3.4.2
    ./configure
    make
    sudo make install
    cd ..
    
    wget http://download.osgeo.org/gdal/1.10.1/gdal1101.zip
    unzip gdal1101.zip
    cd gdal-1.10.1
    ./configure --with-python=yes
    make
    sudo make install
    cd ..
    
    wget http://download.osgeo.org/postgis/source/postgis-2.1.1.tar.gz
    tar -xvf postgis-2.1.1.tar.gz
    cd postgis-2.1.1
    ./configure
    make
    sudo make install