There are 2 methods in this class which should be able to help you. One is for if you need to pass if there a payload, the other if the payload is null.
You should know that the function name may not be the same as the handler.
So, if you have a function with the function name 'myFunction' that behind the scenes invokes your example. Orders::orderHandler handler, then this is what you would pass into the run methods below.
import com.amazonaws.regions.Regions;
import com.amazonaws.services.lambda.AWSLambdaAsyncClient;
import com.amazonaws.services.lambda.model.InvokeRequest;
import com.amazonaws.services.lambda.model.InvokeResult;
class LambdaInvoker {
public void runWithoutPayload(String region, String functionName) {
runWithPayload(region, functionName, null);
}
public void runWithPayload(String region, String functionName, String payload) {
AWSLambdaAsyncClient client = new AWSLambdaAsyncClient();
client.withRegion(Regions.fromName(region));
InvokeRequest request = new InvokeRequest();
request.withFunctionName(functionName).withPayload(payload);
InvokeResult invoke = client.invoke(request);
System.out.println("Result invoking " + functionName + ": " + invoke);
}
}