2

I have a C# lambda function that is called from API gateway using a GET request.

[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
public ResponseModel MyFunction(RequestModel request)
{
    return new ResponseModel { body = "Hello world!" };
}

public class RequestModel 
{
    [JsonProperty("a")]
    public string A { get; set; }

    [JsonProperty("b")]
    public string B { get; set; }
}

public class ResponseModel 
{
    public int statusCode { get; set; } = 200;
    public object headers { get; set; } = new object();
    public string body { get; set; } = "";
}

How do I map the query string parameters sent to API gateway to the RequestModel parameter in MyFunction?

I have called the function with parameters but they don't seem to come through. Is there a wait to achieve this with a C# lambda function?

Thanks,

Chris

1 Answer 1

3

Try putting this in your RequestModel:

public class RequestModel 
{
   [JsonProperty("queryStringParameters")]
   public Dictionary<string, string> QueryStringParameters { get; set; }
}

Then access the query string values as request.QueryStringParameters["foo"], etc.

If you checked the Use Lambda Proxy integration box in API Gateway for your resource and method (which I suspect you did, since you've structured your response object with the statusCode, headers, and body fields), the corresponding request object structure is documented in Input Format of a Lambda Function for Proxy Integration, buried deep in AWS's documentation. There are also other fields available like the body, headers, HTTP verb, etc.

My understanding is that you can also create a custom Payload Mapping to map different parts of the request to a custom JSON object, but doing so requires more configuration than using the built-in Lambda Proxy.

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

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.