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
- Using AWS Elastic Beanstalk configuration files (
- Using Elastic Beanstalk AWS Console
Using AWS Elastic Beanstalk configuration files (
.ebextensions folder to your web application’s directory and create a new file named
newrelic-java.config inside the
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
- 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.jarto the JVM.
- Set the App Name and License key using Environment variables.
Kindly find the contents of the
newrelic-java.config file below:
--- commands: 01-download-java-agent: command: "sudo curl --location https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip > /var/newrelic-java.zip" 02-unzip-java-agent: command: "unzip /var/newrelic-java.zip -d /var/" 03-Give-permissions-to-newrelic: command: "chmod a+rwx /var/newrelic" option_settings: - 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"
INSERT_APP_NAMEwith your App Name and
INSERT_LICENSE_KEYwith your New Relic license key.
Deploy your app to Elastic BeanStalk.
Using AWS Elastic Beanstalk Console
Before completing this configuration, you must first:
- Create a supported Amazon Web Services account
- Create a New Relic account
- Download and install the Java agent
To complete Java agent installation on AWS Elastic Beanstalk:
- Add the
newrelic.ymlfiles 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.jarswitch 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:
- 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.jarfile. This should be in
- Once you locate the
readlink -f newrelic.jarcommand will print out the full file path
-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:
- Which should look similar to this:
- 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.