aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Log4j2 Incompatibility with SAM

Open volodymyr-f opened this issue 9 years ago • 2 comments

Hi Guys,

I'm facing very strange issue that when I'm adding log4j2 configuration my functions stops to work correctly.

I have a project that contains dependencies to https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-log4j2 and when everything is done according to instructions My functions stops to work correctly and returns:

Function returned an invalid response (must include one of: body, headers or statusCode in the response object): invalid character '-' after top-level

When I copy log4j2.xml to src/main/resources in maven function works fine but as expected log4j2 configuration can't be found

START RequestId: aa632e55-8cd9-4b7e-9d3f-196cdab74f9e Version: $LATEST Save started...ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging.

..... End everything is green.

After playing with this issue it looks like that even simple sysout with text breaks overal execution and Error is returned: Function returned an invalid response (must include one of: body, headers or statusCode in the response object): invalid character '-' after top-level

It looks like if I put simple sysout in any place of code that will be executed AWS Sam will crash.

e.g.: Such function works fine:

public class Function implements RequestStreamHandler { @Override public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException

//My Code }}

And such code crashes:

public class Function implements RequestStreamHandler { @Override public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException System.out.println("Hi"); //My Code }}

volodymyr-f avatar Dec 02 '17 22:12 volodymyr-f

I'm having the same problem. Log4j2 works fine when deployed to AWS but fails when I try to run the lambda using sam local.

rbbhar avatar Jan 26 '18 00:01 rbbhar

This should work in latest version of SAM CLI v0.3.0. Can you check and re-open if it doesn't?

sanathkr avatar Jun 01 '18 00:06 sanathkr