Reputation: 3197
I am trying to launch an app on elastic beanstalk in the php 5.5 container. there are 3 environments dev, staging and production. You cannot distinguish between environments when setting environment variables from the command line so I am using a workaround suggested by aws support which is to run a shell script on deployment to set the variables depending on the existence of another variable I can vary depending on environment
.When i deploy my app there is a config file in .ebextensions/ like so
container_commands:
command01:
command: "./.ebextensions/setEnvVars.sh"
the shell script is also in .ebextensions and it looks like so
#!/bin/bash
case "$PARAM1" in
"development")
echo -e "SetEnv APP_ENV development\n
SetEnv DB_HOST *******\n
SetEnv DB_NAME *******\n
SetEnv DB_USERNAME *******\n
SetEnv DB_PASSWORD *******\n" > .htaccess
;;
"production")
echo -e "SetEnv APP_ENV production\n
SetEnv DB_HOST *******\n
SetEnv DB_NAME *******\n
SetEnv DB_USERNAME *******\n
SetEnv DB_PASSWORD *******\n" > .htaccess
;;
"staging")
echo -e "SetEnv APP_ENV staging\n
SetEnv DB_HOST *******\n
SetEnv DB_NAME *******\n
SetEnv DB_USERNAME *******\n
SetEnv DB_PASSWORD *******\n" > .htaccess
;;
esac
if [ -f .htaccess ]; then
chmod 644 .htaccess
fi
when the app deploys I get this error
[Instance: i-400fc60f Module: AWSEBAutoScalingGroup ConfigSet: null] Command failed on instance. Return code: 1 Output: Error occurred during build: Command command01 failed .
and this is what I think is the relevant ecert from the logs
2014-02-03 12:54:25,531 [INFO] (1923 MainThread) [command.py-130] [root command execute] Command returned: (code: 1, stdout: Error occurred during build: Command command01 failed
, stderr: None)
2014-02-03 12:54:25,533 [DEBUG] (1923 MainThread) [commandWrapper.py-60] [root commandWrapper main] Command result: {'status': 'FAILURE', 'results': [{'status': 'FAILURE', 'config_sets': ['Infra-WriteRuntimeConfig', 'Infra-WriteApplication1', 'Infra-WriteApplication2', 'Infra-EmbeddedPreBuild', 'Hook-PreAppDeploy', 'Infra-EmbeddedPostBuild', 'Hook-EnactAppDeploy', 'Hook-PostAppDeploy'], 'returncode': 1, 'events': [], 'msg': 'Error occurred during build: Command command01 failed\n'}], 'api_version': '1.0'}
I don't have any experience with elastic beanstalk or shell so there could easily be a syntax error but I honestly dont know were to look
Upvotes: 1
Views: 2208
Reputation: 2129
A useful trick for debugging issues with scripts is to redirect stdout/stderr to a file.
commands:
command-00:
command: my_command args >> commands.out 2&>1
Upvotes: 1
Reputation: 746
Ah, but this is why working with .ebextentions
is such great fun!
From the log you appended, the only thing I'm able to see is that it's in fact your command named command01
that failed. Exactly what went wrong is typically an enigma of trial-and-error.
This is exactly the place to bring back any old skills you may have in "printf()-debugging". Anything you echo from the scripts you call will also be output into the same log file (/var/log/cfn-init.log
), allowing you to grok what's going on...
Looking at your scripts, however, my guess would be that $PARAM1 is undefined. Try passing it as a parameter to your shell script in your container_command
like so:
container_commands:
command01:
command: "./.ebextensions/setEnvVars.sh" ${PARAM1}
And then use the first argument in your Bash case
statement:
#!/bin/bash
case "$1" in
...
esac
Good luck!
Edit: Oh, one more thing. You'll of course need to set the PARAM1
parameter in your AWS Console. You do this in Configuration
> Software Configuration
> Environment Properties
. Just in case you haven't done this already...
Upvotes: 2