S3Event is part of the AWS Lambda Java Events library where Context is part of the AWS Lambda Java Core. When you include the events library you do pull in the 1.x Java SDK. However, if you use the Java Stream version of the Lambda handler you can remove the dependency to the events library and thus remove your need for the 1.x SDK. Your code would look something like:

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.jayway.jsonpath.JsonPath;


public class S3EventLambdaHandler implements RequestStreamHandler {
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {

        try {
            List<String> keys = JsonPath.read(inputStream, "$.Records[*].s3.object.key");

            for( String nextKey: keys )
                System.out.println(nextKey);
        }
        catch( IOException ioe ) {
            context.getLogger().log("caught IOException reading input stream");
        }
    }
}

then you can read the JSON that is in the S3Event yourself. In effect, you're doing the serialization of the S3Event in your code instead of having the Amazon library do it.

Obviously the biggest downside is that you have to serialize the event yourself. An example S3 event in JSON can be found here.

The above example uses JsonPath to pull out, in this case, the keys from the event. You'll be amazed how much smaller your Lambda code is after you remove the Lambda Events library.

Edit - September 2022

I know it's not clear sometimes but the AWS Lambda Core Library for Java does not have a version 2 - even 4 years after this post. The Lambda Core library defines things like Context and RequestStreamHandler as shown in my code above. As of this writing, there are still 3 libraries that can be used for writing the server side of a Lambda in Java and they are all still in the com.amazonaws package. These are not the libraries for accessing, as a client, the rest of AWS for which there are the V2 (in the software.amazon package) libraries. The answer to the OP's question is still the same - a V2 library for writing the server side of a Lambda in Java does not exist. Interacting, as a client, with the rest of the AWS environments - sure, there has been a V2 for quite a while. But not the "server" side of a Lambda.

The AWS Lambda Java Events library is now on V3 and yet it still uses the com.amazonaws package. For reference, I would write the code above without using a RequestStreamHandler as the events library is much lighter than it was 4 years ago but that doesn't change the package name.

Answer from stdunbar on Stack Overflow
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 2.x › sdk for java 2.x code examples › lambda examples using sdk for java 2.x
Lambda examples using SDK for Java 2.x - AWS SDK for Java 2.x
Shows how to create an AWS Lambda function by using the Lambda Java runtime API. This example invokes different AWS services to perform a specific use case.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with java
Building Lambda functions with Java - AWS Lambda
The console creates a Lambda function with a handler class named Hello. Since Java is a compiled language, you can't view or edit the source code in the Lambda console, but you can modify its configuration, invoke it, and configure triggers.
Discussions

amazon web services - How to create a Lambda function using AWS SDK for Java 2.0 - Stack Overflow
Using java SDK 2.x, I can't seem to find the equivalent dependencies for S3Event and Context object? I would really appreciate if someone could point me to examples. Or should I just stick to using SDK 1.x if 2.x is not mature enough for handling lambda? ... S3Event is part of the AWS Lambda ... More on stackoverflow.com
🌐 stackoverflow.com
In what scenario does using Java in Lambda make sense?
Very often the best language for a team/org is not the "best" language for particular component. If it's a Java based team it often doesn't make sense to dump all that investment just for Lambda if Java performance there is acceptable. Personally I won't use Node for anything if I can possibly avoid it. If Python isn't fast enough and in particular if threading will help I'll use Go. But even as anti-Node as I admit I am, I absolutely respect that in shops with a lot of Javascript talent due to frontend work it often makes the most sense to go with Node for backend work despite its many hair pulling issues. It's much better to be pragmatic than "right". Lambda supports a ton of languages (effectively all of them if we count custom runtimes) because it's pragmatic. More on reddit.com
🌐 r/aws
62
25
March 28, 2024
Why has Java fallen out of favor for use in lambdas?
Were they ever IN favor? Cold start times for JVM based lambdas were awful when I experimented with them a few years ago. I've read recently that improvements have been made, but honestly I like my lambdas to be extremely light weight, so interpreted languages just feel more in line with what I'm doing. More on reddit.com
🌐 r/aws
52
8
November 28, 2022
Java for AWS Lambda
Keep it simple and you will be good. We follow the following for all our lambdas: Use plain SQL query instead of jpa don't use Spring Boot or any other framework if your use case is simple you don't need dependency injection for simple use case that involves couple of classes. Just create static objects and pass them around. Create objects ( eg objectMapper, AWS clients) only once use RDS proxy instead of creating DB connection directly use SnapStart use shadow jar use minimal dependencies.. exclude unnecessary transitive dependencies if you do http calls to other services make sure they are performant. If possible use async calls, parallelize calls if possible use lightweight objects, don't use xml, Json libraries if you can(most of the time simple String append is faster) run the lambda locally and profile it etc More on reddit.com
🌐 r/java
46
41
October 2, 2024
Top answer
1 of 1
8

S3Event is part of the AWS Lambda Java Events library where Context is part of the AWS Lambda Java Core. When you include the events library you do pull in the 1.x Java SDK. However, if you use the Java Stream version of the Lambda handler you can remove the dependency to the events library and thus remove your need for the 1.x SDK. Your code would look something like:

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.jayway.jsonpath.JsonPath;


public class S3EventLambdaHandler implements RequestStreamHandler {
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {

        try {
            List<String> keys = JsonPath.read(inputStream, "$.Records[*].s3.object.key");

            for( String nextKey: keys )
                System.out.println(nextKey);
        }
        catch( IOException ioe ) {
            context.getLogger().log("caught IOException reading input stream");
        }
    }
}

then you can read the JSON that is in the S3Event yourself. In effect, you're doing the serialization of the S3Event in your code instead of having the Amazon library do it.

Obviously the biggest downside is that you have to serialize the event yourself. An example S3 event in JSON can be found here.

The above example uses JsonPath to pull out, in this case, the keys from the event. You'll be amazed how much smaller your Lambda code is after you remove the Lambda Events library.

Edit - September 2022

I know it's not clear sometimes but the AWS Lambda Core Library for Java does not have a version 2 - even 4 years after this post. The Lambda Core library defines things like Context and RequestStreamHandler as shown in my code above. As of this writing, there are still 3 libraries that can be used for writing the server side of a Lambda in Java and they are all still in the com.amazonaws package. These are not the libraries for accessing, as a client, the rest of AWS for which there are the V2 (in the software.amazon package) libraries. The answer to the OP's question is still the same - a V2 library for writing the server side of a Lambda in Java does not exist. Interacting, as a client, with the rest of the AWS environments - sure, there has been a V2 for quite a while. But not the "server" side of a Lambda.

The AWS Lambda Java Events library is now on V3 and yet it still uses the com.amazonaws package. For reference, I would write the code above without using a RequestStreamHandler as the events library is much lighter than it was 4 years ago but that doesn't change the package name.

Find elsewhere
🌐
Medium
srilalitha1310.medium.com › invoking-an-aws-lambda-in-java-using-aws-sdk-v2-f074f495454a
Invoking an AWS lambda in Java using AWS SDK V2 | by Srilalitha S | Medium
October 27, 2020 - import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.services.lambda.LambdaClient; import software.amazon.awssdk.services.lambda.model.InvokeRequest; import software.amazon.awssdk.services.lambda.model.InvokeResponse; . . @Mock private LambdaClient lambdaClient; @Captor private ArgumentCaptor<InvokeRequest> invokeRequestArgumentCaptor; .
🌐
DZone
dzone.com › software design and architecture › cloud architecture › write your first aws lambda in java
Write Your First AWS Lambda in Java
September 21, 2020 - Learn how to create your first Lambda handler in Java using AWS SDK. Easy to follow step by step tutorial to learn AWS Cloud Development
🌐
AWS
sdk.amazonaws.com › java › api › latest › software › amazon › awssdk › services › lambda › LambdaClient.html
LambdaClient (AWS SDK for Java - 2.42.27)
Create an instance of LambdaWaiter using this client. ... Value for looking up the service's metadata from the ServiceMetadataProvider. ... (AddLayerVersionPermissionRequest addLayerVersionPermissionRequest) throws InvalidParameterValueException, ResourceConflictException, ServiceException, TooManyRequestsException, PolicyLengthExceededException, ResourceNotFoundException, PreconditionFailedException, AwsServiceException, SdkClientException, LambdaException
🌐
Baeldung
baeldung.com › home › cloud › a basic aws lambda example with java
A Basic AWS Lambda Example With Java |Baeldung
April 17, 2025 - In this tutorial, we’ll explore how to create a basic AWS Lambda function using Java.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with java › java sample applications for aws lambda
Java sample applications for AWS Lambda - AWS Lambda
A Java function that demonstrates how you can use Lambda to process orders. This function illustrates how to define and deserialize a custom input event object, use the AWS SDK, and output logging.
🌐
Sumo Logic
sumologic.com › home › how to create and monitor an aws lambda function in java 11
How to create and monitor an AWS lambda function in java ...
December 15, 2025 - AWS Lambda lets a developer create a Lambda Java function, which can be executed in the AWS Cloud. Learn how to upload and test your Lamba Java function through the AWS Console.
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 1.x › aws sdk for java code examples › amazon swf examples using the aws sdk for java › lambda tasks
Lambda Tasks - AWS SDK for Java 1.x
DocumentationAWS SDK for JavaDeveloper Guide for version 1.x · Set up a cross-service IAM role to run your Lambda functionCreate a Lambda functionRegister a workflow for use with LambdaSchedule a Lambda taskHandle Lambda function events in your deciderReceive output from your Lambda ...
🌐
DEV Community
dev.to › amarpreetbhatia › getting-started-with-the-aws-sdk-for-java-and-lambda-40on
Getting Started with the AWS SDK for Java and Lambda - DEV Community
January 9, 2023 - In this article, I will provide a step-by-step guide for setting up Java and Maven to use the AWS SDK for Lambda. By the end of this tutorial, you will have a solid understanding of how to use Java to work with AWS Lambda and incorporate serverless computing into your Java-based projects.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with java › define lambda function handler in java
Define Lambda function handler in Java - AWS Lambda
Setting up your Java handler projectExample Java Lambda function codeValid class definitions for Java handlersHandler naming conventionsDefining and accessing the input event objectAccessing and using the Lambda context objectUsing the AWS SDK for Java v2 in your handlerAccessing environment ...
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › lambda sample applications
Lambda sample applications - AWS Lambda
This function illustrates how to define and deserialize a custom input event object, use the AWS SDK, and output logging. ... – A collection of Java functions that contain skeleton code for how to handle events from various services such as Amazon API Gateway, Amazon SQS, and Amazon Kinesis. These functions use the latest version of the aws-lambda-java-events library (3.0.0 and newer).
🌐
Lumigo
lumigo.io › guides › aws lambda 101 › aws lambda java
AWS Lambda Java - Lumigo
September 17, 2024 - To build a Lambda function with Java, you need to first write code using the handler methods supported by the AWS Java SDK. Then, you need to build the function using build tools like Maven and Gradle.
🌐
GitHub
github.com › alfonsof › aws-java-v2-examples
GitHub - alfonsof/aws-java-v2-examples: Java examples on AWS (Amazon Web Services) using AWS SDK for Java (SDK V2). How to manage EC2 instances, Lambda Functions, S3 buckets, etc.
If you have to use AWS SDK for Java (SDK V1) you have the Java code examples on AWS following this link: https://github.com/alfonsof/aws-java-examples/ You must have an AWS (Amazon Web Services) account. The code for the samples is contained in individual folders on this repository. For instructions on running the code, please consult the README in each folder. ... awslambdahello - AWS Lambda Function Hello World: Example of how to handle an AWS simple Lambda function and a text input.
Starred by 2 users
Forked by 4 users
Languages   Java 100.0% | Java 100.0%
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Serverless-AWS-Lambda-example-in-Java
Create your first Java AWS Lambda function in minutes
If you haven't created a Java-based AWS Lambda function before, you'll be amazed at how easy it is. This quick AWS, Lambda and Java tutorial will quickly get you started in the world of serverless ...