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 th
Here in alternative answer with which the python3 bindings for gdal will work in the AWS EB instance. pygdal is a nice package for “virtualenv and setuptools friendly version of standard GDAL python bindings”, but does not support 1.7.3, which is the gdal version installed using sudo yum -y install gdal gdal-devel
, e.g this answer.
Thus, I had to install an updated gdal and also setup linkages to go with it. This method draws on information in yellowcap’s, radek’s and various other Stackoverflow posts.
As yellowcap said, you must set ENVIRONMENT VARIABLES that make the library linkages you need. In the AWS EB console, Configuration --> Software configuration, edit the Environment Properties adding:
LD_LIBRARY_PATH
= “/usr/local/lib/:$LD_LIBRARY_PATH”
LD_PRELOAD
= ”/usr/lib/libgdal.so.1
Put the following in your .ebextensions folder at the base of your repository:
django.config:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: “.settings.server_settings"
PYTHONPATH: "$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: “/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
commands:
01_yum_update:
command: sudo yum -y update
02_pip_upgrade:
command: /opt/python/run/venv/bin/pip install --upgrade pip
ignoreErrors: false
packages:
yum:
postgresql95-devel: []
git: []
libffi-devel: []
container_commands:
01_migrate:
command: "python manage.py migrate"
leader_only: true
02_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput”
gdal.config
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/01_install_gdal_prerequisites.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
sudo yum install -y gcc-c++ gcc libpng libtiff postgresql95-devel git libffi-devel libxml2-devel libxslt-devel htop
wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz
tar -zvxf proj-4.9.3.tar.gz
cd proj-4.9.3
./configure
make -j 2
sudo make install
cd ..
rm proj-4.9.3.tar.gz
wget http://download.osgeo.org/gdal/2.3.2/gdal-2.3.2.tar.gz
tar -zvxf gdal-2.3.2.tar.gz
cd gdal-2.3.2
./configure --with-static-proj4=/usr/local/lib --with-python --with-threads --with-pg=/usr/bin/pg_config
make -j 2
sudo make install
cd ..
rm gdal-2.3.2.tar.gz
ln -s /usr/local/lib/libgdal.so /usr/lib/libgdal.so.1
sudo ldconfig
in requirements.py include the pygdal package
pygdal==2.3.2.4
You must be sure that the gdal version number matches the pygdal version number, see pygdal documentation.
Result
The following works the EC2 instance virtual env, where your django project is located:
$ python manage.py shell
In [1]: from osgeo import gdal
In [2]: