I have an AWS Lambda function (API) that returns a result based on some parameters. I want to pass the parameters from my C# controller and consume the returned result as well. How can I call my Lambda API from the C# controller?
3
-
Can you clarify what you mean by "I have an AWS Lambda function (API)"? Did you expose the Lambda function via API Gateway? Or are you wanting to call the function directly?Mark B– Mark B2016-10-17 17:38:51 +00:00Commented Oct 17, 2016 at 17:38
-
Yes, it is exposed via the API Gateway. I need to invoke the function in my C# controller and use the results returned by the lambda function. Does that clarification help?proficio20– proficio202016-10-17 18:31:31 +00:00Commented Oct 17, 2016 at 18:31
-
1If you are calling it via API Gateway then this just becomes a question of how to call an API endpoint over HTTP and process a JSON response, which I'm sure there are tons of tutorials and examples for. The fact that the API is in front of a Lambda function would be irrelevant.Mark B– Mark B2016-10-17 18:34:10 +00:00Commented Oct 17, 2016 at 18:34
Add a comment
|
1 Answer
somethings like this:
AmazonLambdaClient alc = new AmazonLambdaClient(AWSAccessKey, AWSSecretKey, RegionEndpoint.USEast1);
Amazon.Lambda.Model.InvokeRequest ir = new Amazon.Lambda.Model.InvokeRequest();
ir.FunctionName = "arn:YOUR_FUNCTIONS_ARN";
ir.Payload = SOME_JSON_ARGUMENTS;
var res = alc.Invoke(ir);
var yourResult = DESERIALIZE_SOMEHOW(res.Payload);