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 Overflowjava - What's the AWS SDK V2 Maven lib for Lambda? - Stack Overflow
amazon web services - AWS Java SDK Version For Creating a Lambda - Stack Overflow
In what scenario does using Java in Lambda make sense?
AWS SDK Java V2 invoke Lambda without wait
Videos
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.
Similar to this answer, you don't have to import all of SDKv1 into your project and should continue to import just aws-lambda-java-core (in addition to SDKv2). It contains a subset of the classes sufficient for implementing an entry point, with the same fully-qualified names as in v1.
In addition, if you need event interfaces like S3Event you can pull in aws-lambda-java-events.
However I am trying to use the latest SDK as recommended here but this is completely different and the
RequestHandlerinterface doesn't appear to exist anymore.
You're using wrong a dependency. This is an SDK for using AWS Services via its REST API, like:
- Putting an object to S3
- Listing EC2 instances
- Deleting an item from AWS DynamoDB
- Invoking a Lambda
- …
I.e. this is an SDK for working with various AWS services. It consists of many libraries, like aws-java-sdk-s3, aws-java-sdk-dynamodb. aws-java-sdk-lambda is one of them, but it is for interacting with Lambda API and not for authoring Lambdas.
The libraries you need for authoring Lambdas are:
com.amazonaws:aws-lambda-java-corecom.amazonaws:aws-lambda-java-events
As you see, those are different. First provides Handler interfaces you're looking for and second contains various events Lambda can accept as input: SNS events, CloudWatch timers and so on.
From here:
Lambda supports two approaches for creating a handler:
Loading the handler method directly without having to implement an interface. This section describes this approach.
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).
Here is aws-lambda-java-core