AWS Lambda
Developer Guide

Building Lambda Functions with Java

The following sections explain how common programming patterns and core concepts apply when authoring Lambda function code in Java.

Java Runtimes

Name Identifier JDK Operating System

Java 8

java8

java-1.8.0-openjdk

Amazon Linux

AWS Lambda provides the following libraries for Java functions:

  • aws-lambda-java-core – This library provides the Context object, RequestStreamHandler, and the RequestHandler interfaces. The Context object (AWS Lambda Context Object in Java) provides runtime information about your Lambda function. The predefined interfaces provide one way of defining your Lambda function handler. For more information, see Leveraging Predefined Interfaces for Creating Handler (Java).

  • aws-lambda-java-events – This library provides predefined types that you can use when writing Lambda functions to process events published by Amazon S3, Kinesis, Amazon SNS, and Amazon Cognito. These classes help you process the event without having to write your own custom serialization logic.

  • Custom Appender for Log4j2.8 – You can use the custom Log4j (see Apache Log4j 2) appender provided by AWS Lambda for logging from your lambda functions. Every call to Log4j methods, such as log.info() or log.error(), will result in a CloudWatch Logs event. The custom appender is called LambdaAppender and must be used in the log4j2.xml file. You must include the aws-lambda-java-log4j2 artifact (artifactId:aws-lambda-java-log4j2) in the deployment package (.jar file).For more information, see AWS Lambda Function Logging in Java.

These libraries are available through the Maven Central Repository and can also be found on GitHub.