LoginSignup
2
1

More than 5 years have passed since last update.

Elastic Beanstalkで環境変数の存在に応じてコマンド実行

Last updated at Posted at 2016-10-20

What

Elastic Beanstalkで環境変数が存在する場合のみ、特定のコマンドを実行したい

How

.ebextensionsに書く。

例えば、newrelicのキーが存在(production環境とか)によって設定をしたい場合、以下のようにする

.ebextensions/newrelic.config
# newrelic
packages: 
  yum: 
    newrelic-sysmond: [] 
  rpm: 
    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
container_commands: 
  "01": 
    command: test -v $NEWRELIC_KEY || nrsysmond-config --set license_key=$NEWRELIC_KEY
  "02": 
    command: test -v $NEWRELIC_KEY || echo hostname=$HOSTNAME >> /etc/newrelic/nrsysmond.cfg 
  "03": 
    command: test -v $NEWRELIC_KEY || /etc/init.d/newrelic-sysmond start
  "04": 
    command: test -v $NEWRELIC_KEY || sed -i -e "s/API_KEY/$NEWRELIC_KEY/" config/newrelic.yml

Notes

  • test -vでチェック
  • container_commandsを使わないとebextentions内で環境変数が取れない
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1