1

我在 API Gateway 中创建并部署了一个简单的 GET API,这里是 ARN,这个函数没有任何身份验证,我可以简单地在我的浏览器上调用它

arn:aws:lambda:ap-southeast-1:XXXXXXXXXXXXXX:function:La

并且可以使用浏览器浏览的公共url是:

https://xxxxxxxxx.execute-api.ap-southeast-1.amazonaws.com/v1/lambda/geta

我正在使用 Spring Boot 项目和下面的代码来调用 API(遵循这个 Doc

作为 lambda 服务的接口

package com.xxxxxxx.services.interfaces;

import com.amazonaws.services.lambda.invoke.LambdaFunction;

public interface ILambdaGetBalance {

    @LambdaFunction(functionName="La")
        String getA();
    }

使用该接口调用 lambda 函数的服务

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.xxxxxxxx.services.interfaces.ILambdaGetBalance;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.lambda.AWSLambda;
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
import com.amazonaws.services.lambda.invoke.LambdaInvokerFactory;

@Service
public class LambdaService {

    @Value("${aws.access-key}")
    private String accessKey; 

    @Value("${aws.secret-key}")
    private String secretKey;

    @Value("${aws.lambda.region-name}") // this is ap-southeast-1
    private String regionName;

    public void test() {
        AWSCredentials credentials = new BasicAWSCredentials(accessKey,
                secretKey); 
        AWSLambda client = AWSLambdaClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withRegion(regionName)
                .build();

        final ILambdaGetBalance getBalance = LambdaInvokerFactory.builder()
                .lambdaClient(client)
                .build(ILambdaGetBalance.class);

        getBalance.getA();
    }
}

调用 getA 函数后,系统会出现以下异常:

java.lang.NoSuchMethodError: com.amazonaws.services.lambda.AWSLambdaClient.beforeClientExecution(Lcom/amazonaws/AmazonWebServiceRequest;)Lcom/amazonaws/AmazonWebServiceRequest;

知道为什么会这样吗?我错过了什么?

4

1 回答 1

0

看起来您的aws-java-sdk-lambdaaws-java-sdk-core模块可能有不兼容的版本。您如何解决项目的依赖关系?该方法以版本的形式beforeClientExecution添加到AmazonWebServiceClient基类中- 请参见此处:https ://github.com/aws/aws-sdk-java/blame/master/aws-java-sdk-core/src/main/java/com /amazonaws/AmazonWebServiceClient.java#L5901.11.106aws-java-sdk-core

于 2017-04-19T17:08:22.800 回答