How do I map AWS API Gateway query string to C# AWS Lambda function?

前端 未结 1 1669
粉色の甜心
粉色の甜心 2021-01-22 15:51

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

[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
publ         


        
相关标签:
1条回答
  • 2021-01-22 16:38

    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.

    0 讨论(0)
提交回复
热议问题