php - Elastic Beanstalk - set .htpasswd on specific environment -


i have php website configured within elastic beanstalk on 2 environments, production environment , stage environment. within each environment have application_env environment variable set identifies code environment it's running on. don't want stage website accessible public , wanted place htpasswd on environment not on production one.

to try achieve have created configuration within .ebextensions. entire .ebextensions folder has 3 files:

  1. 01stage.config

    container_commands:   command-01:     command: "/bin/bash .ebextensions/set_stage_htpasswd.sh"     leader_only: true 
  2. set_stage_htpasswd.sh

    #!/bin/bash if [ "$application_env" == "stage" ];   cp /var/app/current/.ebextensions/.htpasswd /var/app/current/  fi 
  3. .htpasswd

    my_username:my_password 

i want elastic beanstalk run config file 01stage.config in turn run shell script set_stage_htpasswd.sh copy .htpasswd file specific location.

however when try deploy this:

  1. i error message in 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 .

  2. elastic beanstalk informs me has deployed application , it's running new version hasn't deployed new code , still running previous one.

is right way try , achieve or there better alternative.

i think quotes on command: line giving problems. wouldn't surprised if shell looking strange command... if that's ok, it's easier use test: directive conditionally execute file copy operations want. try along lines:

container_commands:     command-01: cp .ebextensions/.htpasswd /var/app/current     test: "[ .$application_env. = .stage. ]" 

(environment variables are available to container_commands:, i'm not sure -- , you'll need verify -- available in test: part of section.)


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -