Adding environment variables to files within .ebextensions

amazon-web-serviceselastic-beanstalk

I pulled this from the New Relic docs. I'm looking for a way to replace YourNewRelicLicense and NameOfYourServer with environment variables set up on the ec2 instance.

packages: 
  yum: 
    newrelic-sysmond: [] 
  rpm: 
    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm 
commands: 
  "01": 
    command: nrsysmond-config --set license_key=YourNewRelicLicense 
  "02": 
    command: echo hostname=NameOfYourServer >> /etc/newrelic/nrsysmond.cfg 
  "03": 
    command: /etc/init.d/newrelic-sysmond start

Is this possible?

Best Answer

I had the same issue. With a little testing I came up with an updated version of what New Relic provides that allows use of environment variables from the application config in elastic beanstalk.

Final version looked like this

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: /usr/sbin/nrsysmond-config --set license_key=${APP_NR_LIC}
  "02":
    command: echo hostname=$HOSTNAME >> /etc/newrelic/nrsysmond.cfg
  "03":
    command: /etc/init.d/newrelic-sysmond start

Just replace APP_NR_LIC with whatever variable you use to set you license key. This is working reliably for me.

Thanks to Maciej for his research here.

Related Topic