Q:

Add private IP address as JVM option in ebextension

I'm running Tomcat in AWS elastic beanstalk. I need to add a JVM option that includes the private IP address of whatever EC2 instance the code is running on.
I need to add this property to enable JMX: -Djava.rmi.server.hostname=1.2.3.4
I've tried these different ways, but it just adds the literal string as an env property. It works just fine if I hard code the IP address, but it's an auto-scaling setup, so the IP will always be different.
option_settings:
  aws:elasticbeanstalk:application:environment:
    java.rmi.server.hostname: { "Fn::GetAtt" : [ "AWS::EC2::Instance", "PrivateIp"] }
    java.rmi.server.hostname: '`Fn::GetAtt: [ AWS::EC2::Instance, PrivateIp ]`'

If I can't do it in option_settings, is there a way I can create a script to append to the CATALINA_OPTS variable? I tried:
"/opt/elasticbeanstalk/hooks/appdeploy/post/HL_01_add_catalina_opts.sh":
    mode: "000771"
    content : |
      #!/bin/bash
      CATALINA_OPTS="${CATALINA_OPTS} -Djava.rmi.server.hostname=$(hostname -I)

A:

I was able to get it to work by adding this ebextension:
container_commands:
  add_catalina_opts:
    command: echo -e "\nCATALINA_OPTS=\"${CATALINA_OPTS} -Djava.rmi.server.hostname=$(hostname -I)\"\n" >> /usr/share/tomcat8/conf/tomcat8.conf

The tomcat8.conf file is executed in the tomcat startup script, so additional properties can be appended to that file before tomcat is deployed.

