'Payload is empty when using IAmazonLambda.InvokeAsync in the AWS .NET SDK
So I'm using Unity (c#) to implement client-sided integration with Lambda and have imported the AWS .NET SDK (2.0-3.7.200.0) into Unity.
I'm trying to invoke a simple function on Lambda using the SDK, but when I do, the Playload of the response is completely empty. I get no errors or exceptions and the response comes back fine, only I expect to receive the return value of the handler function, but get nothing.
"TestingFunction" on AWS Lambda (index.js):
exports.handler = async (event) => {
let response = {
Success: true,
Result: "Hello from Lambda!"
};
return response;
};
My c# Code for invoking the function:
AWSCredentials Credentials = new CognitoAWSCredentials(IdentityPoolId, RegionEndpoint.GetBySystemName(CognitoIdentityRegion));
IAmazonLambda Client = new AmazonLambdaClient(Credentials, RegionEndpoint.GetBySystemName(LambdaRegion));
public void Invoke()
{
ResultText.text = "Invoking 'TestingFunction' function in Lambda... \n";
InvokeRequest invokeRequest = new InvokeRequest() {
FunctionName = "TestingFunction",
Payload = "",
InvocationType = InvocationType.Event
};
WaitForFunctionInvoke(invokeRequest, m_FunctionInvokeCallback);
}
// Asynchronous function for waiting for function invoke
async void WaitForFunctionInvoke(InvokeRequest request, InvokeFunctionCallback callback)
{
InvokeResponse response = await Client.InvokeAsync(request);
ResultText.text += "\nInvoke Response Received! Invoking callback function..." + "\n";
callback.Invoke(response);
}
// Invoke Function Callback
void OnFunctionInvokeReceived(InvokeResponse response)
{
byte[] responseByteArray = response.Payload.ToArray();
string payloadString = Encoding.ASCII.GetString(responseByteArray);
ResultText.text += "Playload: " + payloadString + "\n";
}
I believe I've setup the AWS sided requirements such as:
- Created a new Cognito Identity Pool for initializing credentials (identity pool id).
- Added all the necessary Permission Policies to the IAM role associated with my identity pool.
I've also used the same c# design for Listing all current Lambda functions, using IAmazonLambda.ListFunctionsAsync(), and that works completely fine.
Any ideas on why the response for the function invoke has no payload?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
