How to match an AWS API Gateway query string with a C # AWS Lambda function?

I have a C # lambda function that is called from an 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 to map request string parameters sent to API gateway to RequestModel parameter in MyFunction ?

I called a function with parameters, but they did not seem to pass. Is there any expectation to achieve this using the C # lambda function?

Thanks,

Chris

+2
source share
1 answer

Try putting this in your RequestModel :

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

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

If you checked the Use Lambda Proxy integration checkbox in the API gateway for your resource and method (which, I suspect, you did because you structured your response object with the statusCode , headers and body fields), the corresponding structure of the request object is documented in the input format lambda - Features for integration with a proxy server , deeply immersed in AWS documentation. There are also other fields available as body, headers, HTTP verb, etc.

I understand that you can also create custom mapping of useful data to map different parts of the request to a custom JSON object, but this requires more configuration than using the built-in Lambda Proxy.

+2
source

All Articles