I really like the approach of calling AWS lambdas from Java described in this blog post.
However, if I have 3 environments (int/test/live), and on each of them the lambda has a slightly different name (created via cloudformation), I can't think of a way to have one interface, and call lambda with a different name depending on the environment.
I am using Spring, and so 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 an interface, this won't be a bean! Is there any way at all to do this? I feel like I hit a brick wall...
Right now I am calling 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();
Obviously with some exception handling here and there. This is not as nice of a solution tho...
For anyone following this, I have submitted an issue and a solution on aws-sdk github. hopefully something similar to my solution will make it to the next release of the SDK...