It seems like you still have to have both SDK v1 and SDK v2 on your classpath.

For example, looking at the Lambda Java documentation you can see that all imports still start with com.amazonaws (SDK v1) and not software.amazon (SDK v2).

One of the examples they list there is blank-java which they describe as "A Java function with the events library, advanced logging configuration, and the AWS SDK for Java 2.x that calls the Lambda API to retrieve account settings"

If you look at that sample application's pom.xml you'll see com.amazonaws and software.amazon packages mixed together.

Similarly for the Lambda handler.

So either they haven't ported everything to SDK v2, or they still want you to use the interfaces from SDK v1 - and then more functional code (non interface code) can be used from SDK v2.

Answer from dutoitns on Stack Overflow
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.

Discussions

update aws lambda java libs to aws sdk java v2
update aws lambda java libs to aws sdk java v2 (https://github.com/aws/aws-sdk-java-v2) More on github.com
🌐 github.com
7
February 1, 2019
AWS SDK Java V2 invoke Lambda without wait
Sources Invoking a Lambda function ... Lambda AWS Lambda Supports Destinations for Asynchronous Invocations ... Adeleke Adebowale .J. ... Thank you for your answer, From all above it seams that the application exit before the asynchronous call has a chance to complete. In order to ensure that the invocation request is sent before the application exits, I had to use future.get() ... Problem with AppSync GraphQL HTTP API call from Lambda function when upgrading from Java SDK V1 to V2... More on repost.aws
🌐 repost.aws
1
0
November 22, 2024
amazon web services - AWS Java SDK Version For Creating a Lambda - Stack Overflow
Implementing standard interfaces provided as part of aws-lambda-java-core library (interface approach). For more information, see Leveraging Predefined Interfaces for Creating Handler (Java). ... Is this library part of the sdk library? I should have also said in my question that I'm trying to follow the recommendation here for use a Maven BOM: docs.aws.amazon.com/sdk-for-java/v2... More on stackoverflow.com
🌐 stackoverflow.com
java - What's the AWS SDK V2 class for Lambda S3Event? - Stack Overflow
aws-lambda-java-events version 3.0.0 was just released with support for all events (including S3) without the inclusion of SDK v1 dependencies. This should help you make use of the AWS SDK for Java v2 and reduce your function package size as the v1 SDK does not need to be bundled anymore if ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 2.x › calling aws services from the aws sdk for java 2.x › invoke, list, and delete aws lambda functions
Invoke, list, and delete AWS Lambda functions - AWS SDK for Java 2.x
The following Java code example demonstrates how to retrieve a list of function names. public static void listFunctions(LambdaClient awsLambda) { try { ListFunctionsResponse functionResult = awsLambda.listFunctions(); List<FunctionConfiguration> list = functionResult.functions(); for (FunctionConfiguration config: list) { System.out.println("The function name is "+config.functionName()); } } catch(LambdaException e) { System.err.println(e.getMessage()); System.exit(1); } }
🌐
GitHub
github.com › aws › aws-lambda-java-libs › issues › 74
update aws lambda java libs to aws sdk java v2 · Issue #74 · aws/aws-lambda-java-libs
February 1, 2019 - update aws lambda java libs to aws sdk java v2 (https://github.com/aws/aws-sdk-java-v2)
Author   SeekerWing
🌐
GitHub
github.com › aws › aws-sdk-java-v2 › blob › master › archetypes › archetype-lambda › README.md
aws-sdk-java-v2/archetypes/archetype-lambda/README.md at master · aws/aws-sdk-java-v2
This is an Apache Maven Archetype to create a lambda function template using AWS Java SDK 2.x. The generated template has the optimized configurations and follows the best practices to reduce start up time.
Author   aws
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with java
Building Lambda functions with Java - AWS Lambda
You can run Java code in AWS Lambda. Lambda provides runtimes for Java that run your code to process events.
🌐
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
The following code example shows how to create an AWS Step Functions state machine that invokes AWS Lambda functions in sequence. ... Shows how to create an AWS serverless workflow by using AWS Step Functions and the AWS SDK for Java 2.x.
🌐
AWS
aws.amazon.com › blogs › developer › tuning-the-aws-java-sdk-2-x-to-reduce-startup-time
Tuning the AWS Java SDK 2.x to reduce startup time | AWS Developer Tools Blog
June 26, 2020 - In this blog post, we will share the best practices on how to optimize your Lambda function using the AWS Java SDK 2.x, so that you can achieve minimal SDK startup time.
Find elsewhere
🌐
AWS re:Post
repost.aws › questions › QU8WHCSFDOTh6RuywUOLMgsg › aws-sdk-java-v2-invoke-lambda-without-wait
AWS SDK Java V2 invoke Lambda without wait | AWS re:Post
November 22, 2024 - Sources Invoking a Lambda function asynchronously - AWS Lambda Invoke - AWS Lambda AWS Lambda Supports Destinations for Asynchronous Invocations ... Adeleke Adebowale .J. ... Thank you for your answer, From all above it seams that the application exit before the asynchronous call has a chance to complete. In order to ensure that the invocation request is sent before the application exits, I had to use future.get() ... Problem with AppSync GraphQL HTTP API call from Lambda function when upgrading from Java SDK V1 to V2
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 2.x › using the aws sdk for java 2.x › reduce sdk startup time for aws lambda
Reduce SDK startup time for AWS Lambda - AWS SDK for Java 2.x
If your runtime requirements are compatible, AWS offers Lambda SnapStart for Java. Lambda SnapStart is an infrastructure-based solution that improves startup performance for Java functions. When you publish a new version of a function, Lambda SnapStart initializes it and takes an immutable, encrypted snapshot of the memory and disk state. SnapStart then caches the snapshot for reuse. In addition to changes that you make to your code, version 2.x of the SDK for Java includes three primary changes that reduce startup time:
🌐
MCP Market
mcpmarket.com › home › agent skills › aws lambda for java (sdk v2)
AWS Lambda Java SDK v2 - Claude Code Skill
March 2, 2026 - Simplifies AWS Lambda service management and function invocation using the AWS SDK for Java 2.x.
🌐
AWS
docs.aws.amazon.com › sdk-for-java › v1 › reference › com › amazonaws › services › lambda › AWSLambda.html
AWSLambda (AWS SDK for Java - 1.12.797)
We announced the upcoming end-of-support for AWS SDK for Java (v1). We recommend that you migrate to AWS SDK for Java v2. For dates, additional details, and information on how to migrate, please refer to the linked announcement. ... Interface for accessing AWS Lambda.
🌐
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; .
🌐
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...
🌐
GitHub
github.com › aws › aws-sdk-java › blob › master › aws-java-sdk-lambda › src › main › java › com › amazonaws › services › lambda › AWSLambda.java
aws-sdk-java/aws-java-sdk-lambda/src/main/java/com/amazonaws/services/lambda/AWSLambda.java at master · aws/aws-sdk-java
The official AWS SDK for Java 1.x (In Maintenance Mode, End-of-Life on 12/31/2025). The AWS SDK for Java 2.x is available here: https://github.com/aws/aws-sdk-java-v2/ - aws-sdk-java/aws-java-sdk-lambda/src/main/java/com/amazonaws/services/lambda/AWSLambda.java at master · aws/aws-sdk-java
Author   aws
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 1.x › aws sdk for java code examples › lambda examples using the aws sdk for java
Lambda Examples Using the AWS SDK for Java - AWS SDK for Java 1.x
We recommend that you migrate to the AWS SDK for Java 2.x to continue receiving new features, availability improvements, and security updates. This section provides examples of programming Lambda using the AWS SDK for Java.
🌐
AWS
docs.aws.amazon.com › aws sdk code examples › code library › code examples by sdk using aws sdks › code examples for sdk for java 2.x › lambda examples using sdk for java 2.x
Lambda examples using SDK for Java 2.x - AWS SDK Code Examples
The following code example shows how to create an AWS Step Functions state machine that invokes AWS Lambda functions in sequence. ... Shows how to create an AWS serverless workflow by using AWS Step Functions and the AWS SDK for Java 2.x.
🌐
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.
These examples show how to use Java 8 and AWS SDK for Java (SDK V2) in order to manage Amazon services on AWS. AWS SDK for Java allows Java developers to write software that makes use of Amazon services like EC2, S3 and Lambda functions.
Starred by 2 users
Forked by 4 users
Languages   Java 100.0% | Java 100.0%