Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Relic Solution: Installing Java agent in AWS Elastic Beanstalk Application



If you are an Amazon AWS Elastic Beanstalk user, the Java agent requires additional configuration.

Here are two options for installing the New Relic Java agent in AWS Elastic Beanstalk

  1. Using AWS Elastic Beanstalk configuration files (.ebextensions )
  2. Using Elastic Beanstalk AWS Console

Using AWS Elastic Beanstalk configuration files (.ebextensions )

Add .ebextensions folder to your web application’s directory and create a new file named newrelic-java.config inside the .ebextensions folder.

The AWS commands key provides a way to execute commands in the underlaying EC2 instance of your Elastic Beanstalk application and the option_settings key provides a way to modify the Elastic Beanstalk configuration using namespaces and configuration options

With these two keys, we were able to develop simple commands packaged in the YAML formatted newrelic-java.config inside the .ebextensions folder to perform the following tasks upon deploying an Elastic Beanstalk Application:

  • Download the current New Relic Java agent to /var directory.
  • Unzip the the downloaded agent.
  • Give a+rwx permissions to the unzipped New Relic folder.
  • Install the Java Agent by passing -javaagent:/full/path/to/newrelic.jar to the JVM.
  • Set the App Name and License key using Environment variables.

Kindly find the contents of the newrelic-java.config file below:

    command: "sudo curl --location > /var/"
    command: "unzip /var/ -d /var/"
    command: "chmod a+rwx /var/newrelic"
    namespace: "aws:elasticbeanstalk:container:tomcat:jvmoptions"
    option_name: "JVM Options"
    value: "-javaagent:/var/newrelic/newrelic.jar -Dnewrelic.config.app_name=INSERT_APP_NAME -Dnewrelic.config.license_key=INSERT_LICENSE_KEY"
  • Replace INSERT_APP_NAME with your App Name and INSERT_LICENSE_KEY with your New Relic license key.

  • Deploy your app to Elastic BeanStalk.

Using AWS Elastic Beanstalk Console

Before completing this configuration, you must first:

To complete Java agent installation on AWS Elastic Beanstalk:

  • Add the newrelic.jar and newrelic.yml files to your project’s WEB-INF/lib/ directory. - Setup your YML file with your license key and App Name
  • Repackage and deploy your project as a new application or an update to a previous application.
  • Next is passing the -javaagent:/full/path/to/newrelic.jar switch to the JVM.

Since Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, auto-scaling. The main problem is finding the AWS path to the newrelic.jar file. One way to figure this out is through Elastic Beanstalk logs.

  • Open the Elastic Beanstalk Management Console.
  • Select your App > navigate to Logs, select Request Logs, and then select the type of logs to retrieve. Last 100 Lines should be enough
  • Open the generated logs, search the logs for “Deploying web application directory” - without the quotation marks
  • Save the directory some where. Eg: /var/lib/tomcat8/webapps/ROOT
  • Locate and connect to the underlaying EC2 instance via SSH. You might need to Authorize Inbound Traffic for Your for the EC2 Instance and also Configure Key Pair for the EC2 Instances in your Elastic Beanstalk Environment before you’ll be able to connect the to EC2 instance.
  • Once connected, find newrelic.jar file. This should be in /WEB-INF/lib/ inside the ROOT folder in /var/lib/tomcat8/webapps/ROOT
  • Once you locate the newrelic.jar file. readlink -f newrelic.jar command will print out the full file path

Passing the -javaagent flag to JVM in AWS Elastic Beanstalk:

  • In the AWS console, open the Elastic Beanstalk.
  • Select the relevant region.
  • Select your application
  • Select Configurations in left pane.
  • Open Software Configuration
  • In the JVM command line options: field, enter: -javaagent:/full/path/to/newrelic.jar
  • Which should look similar to this: -javaagent:/var/lib/tomcat8/webapps/ROOT/WEB-INF/lib/newrelic.jar
  • Select Apply to save. Your Elastic Beanstalk will update your environment.
  • Put some traffic on your app and data should start flowing into your New Relic Account.

Deploying jar to Elastic Beanstalk

This works well for a small company with a few apps, what would you recommend for a large company with a 100+ repo’s? It not really feasible to keep updating repos when there are changes. I would recommend that you provide a solution which makes use of an ebextensions, which installs the latest agent on deployment.


@thrishan Thanks for the feedback on this Relic Solution. We have updated the initial post to include .ebextensions solution. Please let us know your thoughts!


I passed NEW_RELIC_APP_NAME and NEW_RELIC_LICENSE_KEY environment variables to AWS Beanstalk console but can’t get any data.
What should I do?



If you are installing the java agent via AWS console, kindly follow the steps in section called “Using AWS Elastic Beanstalk Console”

  • Remember to add your license key and your app name to newrelic.yml file before you deploy your app

The environment variables are used in the sample script above ONLY with .ebextentions configuration files option.


I am using the AWS Elastic Beantalk Configuration Files and it seems to work if I start a new ELB environment. However, when doing an update, it does not update the environment as expected.


unzip /var/ -d /var/

I found the issue. Running the command above the second time will cause the processor to ask the user if he/she want to overwrite the files. To solve this, simply do:

unzip -o /var/ -d /var/


For using configuration files with glassfish 4, What are the option_settings ? I tried really hard to find with no sucess…


Hey Allan,

Sorry we missed your question. Can you describe what’s happening when you attempt with glassfish? Right now, I’m not seeing specific AWS instructions for glassfish. Although, I see a few references that indicate the glassfish version might be important for the namespace. The values for starting the agent for New Relic will be the same. Essentially, the flag and jar just just need to be passed to the JVM (along with license key, etc.) -javaagent:/path/to/jar

Can you check the beanstalk logs on the instance and see if there’s anything relevant?




For windows, et. al. see:

Let me know if you see anything and post the excerpt here. Otherwise, we can also start a support ticket and you can upload the logs there.




Just updating with new information. I suspect for glasshfish 4 that the setup would be similar. However, the specification is outlined on AWS here:


Glassfish is only available in a preconfigured docker image from AWS elasticbeanstalk - The image can’t be modified. The ONLY option here is to add the newrelic java agent from your DOCKERFILE

See steps here albeit tomcat focused - some tweaks will be needed to work with Glassfish in passing the -javaagent flag to the JVM: Relic Solution: What you need to know about New Relic, when deploying with Docker