4

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#

1

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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')" 

Comments

0

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.

Comments

-1
if (request.QueryStringParameters != null)
{
    queryStringParameters = request.QueryStringParameters;
    foreach (var item in queryStringParameters)
    {
        Console.WriteLine($"QueryStringParameter - " + item.Key + ":" + item.Value);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.