How to install New Relic infrastructure agent to AWS Elastic Beanstalk with Amazon Linux 2
sasurau4
Posted on December 3, 2021
Problem
I want to install New Relic infrastructure agent to Elastic Beanstalk with Amazon Linux2.
The guide is following.
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.
eb setenv NEW_RELIC_LICENSE_KEY=<YOUR_NR_LICENSE_KEY>
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
chmod 755 ./.platform/hooks/prebuild/00_install_nr_agent.sh
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
- https://gist.github.com/hyeoksuhan/c287bc191e5f1757818b9ea0aeeb1b94
- https://docs.newrelic.com/jp/docs/infrastructure/install-infrastructure-agent/config-management-tools/configure-infrastructure-agent-aws-elastic-beanstalk/
- https://docs.newrelic.com/docs/infrastructure/install-infrastructure-agent/linux-installation/install-infrastructure-monitoring-agent-linux/
Posted on December 3, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.