amazon-web-services – Viewing Java Spring Boot Logs from AWS Elastic Beanstalk in AWS CloudWatch

amazon-cloudwatchamazon-web-serviceselastic-beanstalkjavaspringboot

I'm reading the documentation but I'm not understanding simple Java application log access via CloudWatch from AWS Elastic Beanstalk.

I have a simple Java Spring Boot Application deployed on Elastic Beanstalk as a JAR file using the Java Corretto 11 platform with HTTPS. It has successfully created an EC2 instance and a load balancer. I can access the web site via HTTPS. I can see simple access log statistics in the Elastic Beanstalk environment monitoring section.

But where do the Java logs go, and how can I look into them in CloudWatch?

The Using Elastic Beanstalk with Amazon CloudWatch Logs documentation seems to be about the legacy CloudWatch Logs agent, not the new unified CloudWatch agent. Whatever the case, that page says:

Elastic Beanstalk configures log groups in CloudWatch Logs for the various log files that it streams.

But in CloudWatch Logs I have no log groups. So something is wrong already.

My Spring Boot JAR application is running on Elastic Beanstalk. What are my next steps to view the Spring Boot logs in CloudWatch Logs?

Best Answer

The secret is that for the AWS Elastic Beanstalk environment, under Configuration there is a section "Instance log streaming to CloudWatch Logs". The setting Log streaming must be enabled.

This is alluded to in the Using Elastic Beanstalk with Amazon CloudWatch Logs documentation (emphasis added):

When you enable instance log streaming to CloudWatch Logs, Elastic Beanstalk sends log files from your environment's instances to CloudWatch Logs.

Related Topic