简体   繁体   中英

What's the AWS SDK V2 Maven lib for Lambda?

I'm trying to update my project in order to use SDK v2 by using bom configuration. I have updated my pom file but now RequestHandler and Context can't be found. Here is my maven config file

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>software.amazon.awssdk</groupId>
                <artifactId>bom</artifactId>
                <version>2.1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>lambda</artifactId>
        </dependency>
</dependencies>

And my config before which was working

<dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-core</artifactId>
            <version>1.2.0</version>
        </dependency>

Can't seems to find what I should import to have the missing classes. Or in the V2, there is a different signature?

This is my class:

public class Cron implements RequestHandler<Object, Object> {

    public Object handleRequest(final Object input, final Context context) {

Thanks for any pointer.

C.C.

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 .

Perhaps it helps to post your imports here.

As an example for SDK 2.0, in the handler class these seem to be the correct ones (I ran into same problems due to their docs being all over the place with SDK 1 & 2)

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;

Note that I'm also using SQSEvent here, while you're doing the Object and returning the Object.

RequestHandler<Object, Object> 

as opposed to my:

SomeMethodHandler implements RequestHandler<SQSEvent, Void>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM