How to log AWS calls details

After a post about request handlers, we considered it’s time to see a good use case where this feature could be used. What if we create a library that logs in a separate file details about a call to AWS, like latency, response code and so on? Maybe these information are useless in 99.99% of cases, but when you have to debug something, any clue is more than welcome. And sooner or later we have to do investigations.

To this purpose, we created a library very simple to integrate in your application that does exactly what we described above: log details found in a file. Let’s see what are the steps:

  1. Declare the dependency in your pom.xml file
  1. Add the request handler to the AWS client.
AwsLatencyRequestLogHandler handler = new AwsLatencyRequestLogHandler();
  1. Create a new log appender.
<appender name="AWS-APPENDER-LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
   <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
     <!-- hourly rollover -->
     <!-- keep 2 days' worth of history capped at 500MB total size -->
     <pattern>[%thread] %-5level - %d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg%n</pattern>

 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
     <pattern>[%thread] %-5level - %d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg%n</pattern>

  1. Make sure logs are backed in S3 in order to have them later.

The code for this library is available here.

Please add your thoughts in a comment below and if you notice any issue let us know!