Reputation: 41
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#
Upvotes: 4
Views: 3493
Reputation: 682
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
Upvotes: 2
Reputation: 29
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
Step 03: In API > GET Method Execution > Integration Request > Body Mapping Template add this application/json template
"$input.params('strEnvironmentA')"
"$input.params('strEnvironmentB')"
Upvotes: 1
Reputation: 1
Do something like this:
public string FunctionHandler(string input, ILambdaContext context);
And then you can pass the input in the request body instead of query string params.
Upvotes: 0
Reputation: 1
if (request.QueryStringParameters != null)
{
queryStringParameters = request.QueryStringParameters;
foreach (var item in queryStringParameters)
{
Console.WriteLine($"QueryStringParameter - " + item.Key + ":" + item.Value);
}
}
Upvotes: -1