AWS lambda not working with Log4j 2 appender

Qedrix picture Qedrix · Mar 1, 2018 · Viewed 9.6k times · Source

I am trying to write a java based lambda function. Everything works fine except the logging. I have the log4j2.xml file in classpath.

I have also followed the instruction laid down in AWS Lambda LOgging in Java to the word.

I get this in the log when I trigger the Lambda function.

log4j:WARN No appenders could be found for logger (com.amazonaws.AmazonWebServiceClient). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

I use maven to package the jar. The pom.xml has the following dependencies.

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.amazon.alexa</groupId>
  <artifactId>alexa-skills-kit</artifactId>
  <version>${alexa.version}</version>
</dependency>

<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-lang3</artifactId>
  <version>3.4</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.apache.directory.studio</groupId>
  <artifactId>org.apache.commons.io</artifactId>
  <version>2.4</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-lambda-java-core</artifactId>
  <version>1.0.0</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk-dynamodb</artifactId>
  <version>1.9.40</version>
</dependency>
<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-lambda-java-log4j2</artifactId>
  <version>1.0.0</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>2.8.2</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>2.8.2</version>
</dependency>

I am not sure what else I must do to make this work.

Answer

Karl picture Karl · Apr 23, 2018

please note that there is/was a bug in the AWS documentation for lambda logging in java. I have pushed a fix to github for it, but in the mean time see my answer to another post it may be what you need.

tldr; remove .LambdaAppender from the packages attribute of the <Configuration ... tag

see this other stackoverflow question