I'm working on a c# application and using AWS lambda functions in the backend. The lambda function is working correctly and i'm able to call it from the application. The part I'm having trouble with is getting the code to wait for the result from the lambda function to be returned before continuing. I've looked into using the async/await pattern but i'm getting compile errors because AmazonLambda.InvokeAsync returns null.
This is the code what is correctly invoking the function and prints out the response but I'd like to instead return the response to the calling method. I've also tried changing the return from void to string and adding a return to the callback function but I get this error: "Anonymous function converted to a void returning delegate cannot return a value"
Any help is appreciated.
public void Invoke() {
InvokeRequest invokeRequest = new InvokeRequest() {
FunctionName = FunctionName,
Payload = Payload
};
Client.InvokeAsync(invokeRequest, responseObject => {
if (responseObject.Exception == null) {
Debug.Log("LAMBDA SUCCESS: " + Encoding.ASCII.GetString(responseObject.Response.Payload.ToArray()));
} else {
Debug.Log("LAMBDA ERR: " + responseObject.Exception);
}
});
}