Question: I pulled this from the [New Relic](https://docs.newrelic.com/docs/accounts-partnerships/partnerships/partner-based-installation/amazon-web-services-aws-users#lsm) 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?

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](https://stackoverflow.com/users/5552179/maciej) for his research [here](https://stackoverflow.com/a/33660003).
> 
> 
>
Here's an example script that works, and will get environment variables and works with `commands` as opposed to `container_commands`.

```
packages:
  yum:
    newrelic-sysmond: []
  rpm:
    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
files:
  "/root/env.js":
    mode: "00755"
    owner: root
    group: root
    encoding: plain
    content: |
      #!/usr/bin/env node
      var strings = []
      process.stdin.resume()
      process.stdin.setEncoding('utf8')
      process.stdin.on('data', function(data) {
        var json = JSON.parse(data)
        for (var key in json) {
          var val = json[key]
          strings.push(key + '="' + val + '"')
        }
      })
      process.stdin.on('end', function() {
        var output = strings.join('\n')
        process.stdout.write(output)
      })
commands:
  "05":
    command: ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node
  "08":
    command: sudo /etc/init.d/newrelic-sysmond stop
  "09":
    command: sudo /opt/elasticbeanstalk/bin/get-config environment | sudo /root/env.js > file
  "10":
    command: source ./file && sudo nrsysmond-config --set ssl=true license_key=$NEW_RELIC_LICENSE_KEY
  "12":
    command: sudo /etc/init.d/newrelic-sysmond start

```