简体   繁体   English

使用AWS Sdk调用AWS Lambda时的NoSuchMethod

[英]NoSuchMethod when calling AWS Lambda using the AWS Sdk

I've created & deployed one simple GET API in API Gateway and here is the ARN and there is no authentication whatsoever on this function, I can simply call it on my browser 我在API网关中创建并部署了一个简单的GET API,这里是ARN,这个函数没有任何身份验证,我只需在我的浏览器上调用它

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

and the public url that can be browsed using the browser is: 并且可以使用浏览器浏览的公共URL是:

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

and I'm using Spring boot project and the below code to invoke the API (Following this Doc ) 我正在使用Spring启动项目和以下代码来调用API(遵循此Doc

The interface as the lambda service 作为lambda服务的接口

package com.xxxxxxx.services.interfaces;

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

public interface ILambdaGetBalance {

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

The service using that interface to call the lambda function 使用该接口调用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();
    }
}

after calling the getA function the system will through the following exception: 在调用getA函数之后,系统将通过以下异常:

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

Any idea why is this happening? 知道为什么会这样吗? What am I missing? 我错过了什么?

Looks like your aws-java-sdk-lambda and aws-java-sdk-core modules may have incompatible versions. 看起来你的aws-java-sdk-lambdaaws-java-sdk-core模块可能有不兼容的版本。 How are you resolving the dependencies for your project? 您如何解决项目的依赖关系? The beforeClientExecution method was added to the AmazonWebServiceClient base class in version 1.11.106 of aws-java-sdk-core - see here: https://github.com/aws/aws-sdk-java/blame/master/aws-java-sdk-core/src/main/java/com/amazonaws/AmazonWebServiceClient.java#L590 beforeClientExecution方法已添加到aws-java-sdk-core版本1.11.106中的AmazonWebServiceClient基类 - 请参阅: https//github.com/aws/aws-sdk-java/blame/master/aws-java -sdk核/ SRC /主/ JAVA / COM / amazonaws / AmazonWebServiceClient.java#L590

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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