0

I am having two AWS lambda java 8 function "lambda A" and "lambda B". "lambda A" function invokes "lambda B" function and waits till it gets the result of "lambda B". But I want to invoke the "lambda B" and return the "lambda A" function immediately. Is it possible to implement and any reference links related to it.

1 Answer 1

2

With the AWS Lambda SDK for Java you can set the InvocationType within the InvokeRequest object. This will just invoke your function, but won't wait for a response.

From the Javadocs:

By default, the Invoke API assumes RequestResponse invocation type. You can optionally request asynchronous execution by specifying Event as the InvocationType.

Example:

AWSLambda lambdaClient = AWSLambdaClientBuilder.defaultClient();
InvokeRequest request = new InvokeRequest();
request.withFunctionName(name)
       .withInvocationType(InvocationType.Event)
       .withPayload(payload);
InvokeResult result = lambdaClient.invoke(request);

Please also consider reading this and this question.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the clarification. Can you please also clarify me, if I write the "return" next to invoke line. Will it call successfully the lambda B function and also return executes immediately without waiting for the invoke result.
I assume you mean something like this: InvokeResult result = lambdaClient.invoke(request); return ...; ? This will just invoke your function, you'll get a response that it's invoked and you can return whatever you want. See also here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.