DEV Community

sasurau4
sasurau4

Posted on

How to install New Relic infrastructure agent to AWS Elastic Beanstalk with Amazon Linux 2

Problem

I want to install New Relic infrastructure agent to Elastic Beanstalk with Amazon Linux2.

The guide is following.

https://docs.newrelic.com/jp/docs/infrastructure/install-infrastructure-agent/config-management-tools/configure-infrastructure-agent-aws-elastic-beanstalk/

But this guide is not correct about Amazon Linux2.

Why is the document wrong?

The aws official document says,

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.

In Amazon Linux2, it seems that customizing with .ebextensions doesn't work anymore.

We should use https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html instead of .ebextensions

How to install

The solution is following.

  1. eb setenv NEW_RELIC_LICENSE_KEY=<YOUR_NR_LICENSE_KEY>

  2. Put the following content at .platform/hooks/prebuild/00_install_nr_agent.sh

#!/bin/bash
set -e

# NEW_RELIC_LICENSE_KEY has set as one of Elastic Beanstalk Environment properties
NR_LICENSE_KEY=`/opt/elasticbeanstalk/bin/get-config environment -k NEW_RELIC_LICENSE_KEY`
DISPLAY_NAME=<YOUR_APPLICATION_NAME>

sudo cat > /etc/newrelic-infra.yml <<EOL
license_key: ${NR_LICENSE_KEY}
display_name: ${DISPLAY_NAME}
EOL

sudo curl -o /etc/yum.repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/yum/el/7/x86_64/newrelic-infra.repo
sudo yum -q makecache -y --disablerepo='*' --enablerepo='newrelic-infra'
sudo yum install newrelic-infra -y

# Restart the process because the update of config isn't reload automatically
sudo systemctl restart newrelic-infra
Enter fullscreen mode Exit fullscreen mode
  1. chmod 755 ./.platform/hooks/prebuild/00_install_nr_agent.sh

  2. eb deploy

Conclusion

I found Elastic Beanstalk is based on EC2.

I hope the article helps someone to install newrelic agent with EB.

Thanks!

References

Top comments (0)