Barbi
Barbi

Reputation: 188

Read Spring Boot application properties in interface

I have a Spring Boot app which calls some AWS Lambda, like this:

public interface AWSLambdaInvoke {

    @LambdaFunction(functionName = "my-aws-lambda")
    LambdaOutput invokeLambda(LambdaInput lambdaInput);
}

Since I have both prod and dev environment, I would like to have the function name as a property in application.yml file or something similar, so that I can choose which lambda to call depending on my env. Is there a way to achieve this from the interfaces in Java 16?

Upvotes: 0

Views: 1001

Answers (1)

Sobhan
Sobhan

Reputation: 1460

It seems that since version "1.10.51" there is a functionality named as LambdaFunctionNameResolver, you can read more about it here:

https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-lambda/LambdaFunctionNameResolver.java

you may write something like this:

 AWSLambdaInvokeService lambdaInvoke = 
 LambdaInvokerFactory.builder().lambdaClient(AWSLambdaClientBuilder.defaultClient())
.lambdaFunctionNameResolver((method, annotation, config) 
-> generalConfigHelper.getString("name_of_your_function")).build(AWSLambdaInvokeService.class);

Upvotes: 1

Related Questions