Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass QueryString Paramaters from API Gateway to AWS Lambda c#

i am trying to call AWS Lambda using APIGateway and it returns HTML Code. it works fine when i dont pass any parameters, but i want to pass some QueryString parameters and use them in Lambda. i have my Lambda in C# and i see parameters being passed from API

response from API "headers": {}, "QueryStringParameters": { "Environment": "xzc" }, "PathParameters": {} }

In Lambda, the APIGatewayProxyRequest is coming as null API Lambda public string FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)

how do i read the querystring parameters in AWS Lambda in C#

like image 643
ABHILASH SOMA Avatar asked Sep 07 '25 11:09

ABHILASH SOMA


2 Answers

Looks like you just need to check Use Lambda Proxy integration in Integration Request in your API Gateway resource config.

also

you should include:

using Amazon.Lambda.APIGatewayEvents;

and your handler function header should like something like this:

public APIGatewayProxyResponse FunctionHandler( APIGatewayProxyRequest input, ILambdaContext context)

then you can access your query string parameters with:

input.QueryStringParameters

like image 97
Zbigniew Ledwoń Avatar answered Sep 10 '25 22:09

Zbigniew Ledwoń


Explaining for more than 1 input parameters as sometimes that is also a problem to developers:

Step 01: This should be your C-Sharp method

public string FunctionHandler(string strEnvironmentA, string strEnvironmentB, ILambdaContext context);

Step 02: In API > GET Method Execution > Method Request add query string parameter for

  • strEnvironmentA
  • strEnvironmentB

Step 03: In API > GET Method Execution > Integration Request > Body Mapping Template add this application/json template

"$input.params('strEnvironmentA')" 
"$input.params('strEnvironmentB')" 
like image 28
Anugrah A Avatar answered Sep 11 '25 00:09

Anugrah A