Search code examples
amazon-web-servicesamazon-elastic-beanstalknewrelic

Error installing New Relic on AWS Elastic Beanstalk


I have a Java application running fine on Elastic Beanstalk.

I am using Corretto 17 running on 64bit Amazon Linux 2/3.4.8

I was following this guide to use New Relic on Elastic Beanstalk.

However, I get an error:

2023-06-20 21:09:51,402 [ERROR] Command 03-run-installation-script (sudo yum install newrelic-infra -y) failed
2023-06-20 21:09:51,402 [ERROR] Error encountered during build of prebuild_0_zoomies: Command 03-run-installation-script failed
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 576, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 276, in build
    self._config.commands)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
    raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command 03-run-installation-script failed

Nothing else shows more details on the logs, just this, with no explanation on what caused the error.

What I am doing wrong?


Solution

  • From the official AWS Elastic Beanstalk Developer Guide: Customising software on Linux Servers

    On Amazon Linux 2 platforms, instead of providing files and commands in .ebextensions configuration files, we highly recommend that you use Buildfile. Procfile, and platform hooks whenever possible to configure and run custom code on your environment instances during instance provisioning. For details about these mechanisms, see Extending Elastic Beanstalk Linux platforms.

    YAML relies on consistent indentation. Match the indentation level when replacing content in an example configuration file and ensure that your text editor uses spaces, not tab characters, to indent.

    The guide that you followed installed New Relic using .ebextensions and that may be the issue here.

    Below is a process using the platform hooks option, where you run custom shell scripts from this directory: .platform/hooks/prebuild/ for Elastic Beanstalk EC2

    Installing New Relic using Platform Hooks

    1. Setup an Elastic Beanstalk ENVIRONMENT VARIABLE for the New Relic Licence Key

      • Using eb setenv - Sets environment properties for the default environment by setting the following:
        • eb setenv RELIC_KEY=<the value of the new relic licence key>
          • i.e. eb setenv RELIC_KEY=a1b2c3d4e5f6
    2. Create an executable shell script in the following directory:.platform/hooks/prebuild/

      • touch .platform/hooks/prebuild/new_relic_agent.sh
      • chmod 755 .platform/hooks/prebuild/new_relic_agent.sh
    3. Populate the new_relic_agent.sh with the following and persist:

       #!/bin/bash
       set -e
      
       NR_KEY=`/opt/elasticbeanstalk/bin/get-config environment -k RELIC_KEY`
      
       # location and file name based on guide provided in the question
       sudo cat > /etc/newrelic-infra.yml <<EOL
       license_key: ${NR_KEY}
       EOL     
      
       # applying the commands based on guide provided in the question 
       sudo curl -o /etc/yum.repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/yum/amazonlinux/2/x86_64/newrelic-infra.repo
       sudo yum -q makecache -y --disablerepo='*' --enablerepo='newrelic-infra'
       sudo yum install newrelic-infra -y
      
       # restart the service as good practice
       sudo systemctl restart newrelic-infra
      
      
    4. Deploy the agent using the Elastic Beanstalk prebuild process

      • Using eb deploy - Deploys the application source bundle from the initialized project directory to the running application, run the following:
        • eb deploy

    EDIT

    Original answer detailed a curl for generic linux repo, that was incorrect. It has been updated to curl for Amazon Linux 2 x64. Details for all the correct repos can e found here: Install the infrastructure monitoring agent for Linux