I have these container commands in an .ebextensions .config file:
container_commands:
download_geography_data_01:
command: "python scripts/download_geography_data.py"
download_geography_data_02:
command: "file /opt/python/current/app/data/geography/geography.sqlite"
And these execute perfectly when I use eb create
- the second command is just there to put an entry in the log proving that the first script ran correctly and the file was created. I get a line like this in eb_activity.log, exactly as I would expect:
Completed activity. Result: /opt/python/current/app/data/geography/geography.sqlite: SQLite 3.x database
But 2 minutes later, it has my Python web server app is up and running and when it attempts to read that file, it fails:
IOError: geography data file not found. Path searched was /opt/python/current/app/data/geography/geography.sqlite
I then use eb ssh
to log in to my environment, and it's right - the file is not there at all. It has seemingly disappeared between the configuration stage and the execution stage.
Anybody have any idea what could be going wrong? Could it somehow be clearing this file away?
I'm using the "64bit Amazon Linux 2015.03 v1.4.3 running Python 2.7" platform, if that is relevant.
AWS Elastic Beanstalk have never removed your file, except for the app directory.
As AWS Documentation said in Customizing Software on Linux Servers:
You put your SQLite database inside your app directory. When you update to a new one, your change into your old directory will be destroyed.
Before deploying:
On deploying:
After deployed:
Do you notice your
/opt/python/current/app
changed? While on deploying, your/opt/python/current/app
is pointed to/opt/python/bundle/3
. And then after deployed, it is pointed to/opt/python/bundle/4
. And then, the/opt/python/bundle/3
(your old app) is removed.So, the solution might be:
UPDATE: First time deployment and first time update
TLDR: If you create a new environment, the
/opt/python/current
was pointed to/opt/python/bundle/1
and then it will be updated to/opt/python/bundle/2
. So, before your app is deployed, there is a "default" app inside the instance.I create a simple
.ebextensions
script to list all object inside/opt/python
:.ebextensions/env-check.config
In the first deployment (create a new environment using the above
.ebentensions
), I got this:20150730_141343_068692315_00_commands:
20150730_141350_596104854_01_container_commands
20150730_141355_731024404_02_post_deploy
In the second deployment (first update), I got this:
20150730_141535_631911395_00_commands
20150730_141542_258594223_01_container_commands
20150730_141547_336930605_02_post_deploy
From the above result and some checking inside EC2 instance, I can conclude that:
/opt/python/bundle/1
directory before your app come into/opt/python
.commands
in.ebextensions
will be executed before your app file is in/opt/python
.commands
is in/
.container_commands
in.ebextensions
will be executed after your app file is extracted in/opt/python
.container_commands
is in your latest app directory in/opt/python
.I thought, another solution: you can put your SQLite database using current working directory of your script.