We running a PHP web application using AWS Elastic Beanstalk. Been looking at improving our monitoring using CloudWatch logs. Unfortunately the logs are polluted by our health checks originating from our ELB.
Here’s a quick guide on how to stop this.
Using the .ebextensions add the following file into your project (If you haven’t heard about EB extensions, read here.):
.ebextensions/11_apache_dontlog.config
files:
“/etc/httpd/conf.d/dontlog.conf”:
mode: “000644”
owner: root
group: root
content: |
SetEnvIf Request_URI “^/elb-health-check\.php$” dontlog
SetEnvIf Remote_Addr “127\.0\.0\.1” dontlog
SetEnvIf Remote_Addr “::1” dontlogcommands:
“00”:
command: sed -i.bak ‘s+CustomLog “logs/access_log” combined.*+CustomLog “logs/access_log” combined env=!dontlog+’ /etc/httpd/conf/httpd.conf
“01”:
command: apachectl configtest
“02”:
command: service httpd restart
Change the health check URL in the Request_URI, my health check is at /elb-health-check.php. Then simply eb deploy and you should have a clearer view of your logs. 😀
Articles that helped:
JJ