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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.