Determining AWS lambda name at run time in Java

I really like the AWS lambdas call approach from Java described in this blog post .
However, if I have 3 environments (int / test / live), and each of them has a slightly different name for the lambda (created through cloudformation), I cannot think of a way to have one interface and call the lambda with a different name depending on the environment Wednesday.
I use Spring, and therefore, if I could do something like:

@Component
interface MyLambdas {
    @Value("${name}")
    String name;

    @LambdaFunction(name = name)
    String callMyLambda(String stuff);
}

//and then
service = LambdaInvokerFactory.build(MyLambdas.class, lambda);

But obviously I can’t do this on the interface, it won’t bean! Is there any way to do this? I feel like I hit a brick wall ...


Now I call lambda the "old way":

String readLambdaName = "My_Lambda";

ObjectMapper objectMapper = new ObjectMapper();
AWSLambdaClient lambda = new AWSLambdaClient();
lambda.configureRegion(Regions.EU_WEST_1);

String json = objectMapper.writeValueAsString(request);
InvokeRequest req = new InvokeRequest()
        .withFunctionName(readLambdaName)
        .withPayload(json);

InvokeResult res = lambda.invoke(req);
int result = objectMapper.readTree(res.getPayload().array()).asInt();

, . , ...


, , aws-sdk github. , - SDK...

+4
2

, , "lambdaFunctionNameResolver".

//my lambda interface
public interface MyLambdaService {
    @LambdaFunction
    ApiGatewayProxyResponse execute(ApiGatewayRequest bit);
}

-:

MyLambdaService lambdaService = LambdaInvokerFactory.builder().lambdaClient(AWSLambdaClientBuilder.defaultClient())
                    .lambdaFunctionNameResolver((method, annotation, config) -> "ENV_SPECIFIC_FUNCTION_NAME").build(MyLambdaService.class);

"generalConfigHelper.getString(" _ "))" env (dev/qa/prod).

MyLambdaService lambdaService = LambdaInvokerFactory.builder().lambdaClient(AWSLambdaClientBuilder.defaultClient())
                .lambdaFunctionNameResolver((method, annotation, config) -> generalConfigHelper.getString("function_name")).build(MyLambdaService.class);

aws: https://github.com/aws/aws-sdk-java/pull/603

+1

Source: https://habr.com/ru/post/1624241/


All Articles