Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TravisCannon/6023875 to your computer and use it in GitHub Desktop.
Save TravisCannon/6023875 to your computer and use it in GitHub Desktop.
How to add New Relic to an AWS Elastic Beanstalk EC2 for .NET without creating a custom AMI.

Add New Relic To Elastic Beanstalk for .NET

The instructions and files in this Gist can be used to configure an EC2 instance to install both the New Relic .NET Agent and Server Monitor on an EC2 deployed inside of an Elastic Beanstalk, without creating a custom AMI. Once configured, EC2s will begin reporting application and server metrics automatically to New Relic, even as the Elastic Beanstalk scales up and adds more EC2s.


  1. Create a top-level directory in your source bundle called .ebextensions and add newrelic.config to it.
  2. Change the values in newrelic.config to match your configuration, where:
    • download_path_to = URL to download the PowerShell script and New Relic Agents (e.g. an S3 bucket)
    • platform = choose the installer appropriate for your system (i.e. x86 or x64)
    • version = the latest version of the New Relic Agent
    • new_relic_license_key = your New Relic license key
  3. Add an application setting to your application's configuration (i.e. web.config) named NewRelic.AppName, and set its value to the name of the application.
  4. Deploy your application to Elastic Beanstalk.


  • The EnableEc2SetComputerName.ps1 PowerShell script configures the EC2 instance to use a unique computer name based off their private IP address. This allows each server to be reported independently of other EC2 instances sending data to New Relic. Without configuring unique names, EC2s will appear as a single server in NewRelic. This modification to the EC2 requires a reboot.


$EC2SettingsFile="C:\Program Files\Amazon\Ec2ConfigService\Settings\Config.xml"
$xml = [xml](get-content $EC2SettingsFile)
$xmlElement = $xml.get_DocumentElement()
$xmlElementToModify = $xmlElement.Plugins
foreach ($element in $xmlElementToModify.Plugin)
if ($ -eq "Ec2SetComputerName")
source: http://<download_path_to>/EnableEc2SetComputerName.ps1
source: http://<download_path_to>/NewRelicAgent_<platform>_<version>.msi
source: http://<download_path_to>/NewRelicServerMonitor_<platform>_<version>.msi
command: powershell.exe -ExecutionPolicy Bypass -File "C:\\Users\\Public\\Downloads\\EnableEc2SetComputerName.ps1"
command: msiexec.exe /i "C:\\Users\\Public\\Downloads\\NewRelicAgent.msi" /qb NR_LICENSE_KEY=<new_relic_license_key> INSTALLLEVEL=50
command: msiexec.exe /i "C:\\Users\\Public\\Downloads\\NewRelicServerMonitor.msi" /L*v install.log /qn NR_LICENSE_KEY=<new_relic_license_key>
command: powershell.exe -Command "Restart-Computer"
<add key="NewRelic.AppName" value="Your Application Name Here"/>
Copy link

tuler commented Feb 27, 2015

Copy link

will this reinstall the newrelic agents and reboot the servers every time i redeploy the application ?

Copy link

How can I have this not execute on my dev but only on my prod beanstalk ? I am publishing thru my visual studio btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment