When updating your elastic beanstalk with PostgreSQL RDS, you may encounter the following error:
ERROR: Your requirements.txt is invalid. Snapshot your logs for details
There is a known issue with psycopg2 on AWS, and that is the likely cause of the error.
First install some packages so that pip install
command completes successfully. In .ebextensions/01_packages.config:
packages:
yum:
git: []
postgresql93-devel: []
yum is used to install the packages we need, because EC2 instances run on Amazon Linux, which is a Redhat flavor. In the above, we will be installing two packages - git and the Postgres client.
In /.ebextensions/02_python.config:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "iotd.settings"
"PYTHONPATH": "/opt/python/current/app/iotd:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: iotd/iotd/wsgi.py
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python iotd/manage.py migrate --noinput"
leader_only: true
If using Apache with Beanstalk, you could set up Apache to enable gzip compression so files are downloaded faster by the clients. This can be done with container_commands
. In .ebextensions/03_appache.config,
container_commands:
01_setup_apache:
command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"
Then in .ebextensions/enable_mod_deflate.conf,
# mod_deflate configuration
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xml+rss
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
# Level of compression (Highest 9 - Lowest 1)
DeflateCompressionLevel 9
# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
<IfModule mod_headers.c>
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
on-deck
, and then after all the deployment is complete, it will be moved to current
. If you are getting failures in your container_commands
, check out the on-deck
folder and not the current
folder.More can be found about using postgreSQL with EBS here.