I have a PHP website configured within Elastic Beanstalk on two environments, a production environment and a stage environment. Within each environment I have an APPLICATION_ENV environment variable set which identifies to the code which environment it's running on. I don't want my stage website to be accessible to the public and I wanted to place a htpasswd on this environment but not on the production one.
To try to achieve this I have created a configuration within .ebextensions. The entire .ebextensions folder has three files:
01stage.config
container_commands: command-01: command: "/bin/bash .ebextensions/set_stage_htpasswd.sh" leader_only: true
set_stage_htpasswd.sh
#!/bin/bash if [ "$APPLICATION_ENV" == "stage" ]; then cp /var/app/current/.ebextensions/.htpasswd /var/app/current/ fi
.htpasswd
my_username:my_password
I want Elastic Beanstalk to run the config file 01stage.config which will in turn run the shell script set_stage_htpasswd.sh to copy the .htpasswd file to a specific location.
However when I try to deploy this:
I get an error message in the Events log:
Instance: i-2f795c6e Module: AWSEBAutoScalingGroup ConfigSet: null Command failed on instance. Return code: 1 Output: Error occurred during build: Command command-01 failed .
Elastic Beanstalk informs me that it has deployed the application and that it's running the new version but it hasn't actually deployed the new code and is still running the previous one.
Is this is right way to try and achieve this or is there a better alternative.