2017-06-12 57 views
2

我試圖使用API​​Gateway調用AWS Lambda並返回HTML代碼。它工作正常,當我不傳遞任何參數,但我想傳遞一些QueryString參數,並在Lambda中使用它們。我有我的拉姆達在C#中,我看到從API傳遞參數將API網關的QueryString參數傳遞給AWS Lambda c#

response from API "headers": {}, "QueryStringParameters": { "Environment": "xzc" }, "PathParameters": {} }

拉姆達的APIGatewayProxyRequest即將爲空 API Lambda public string FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)

如何閱讀在AWS LAMBDA查詢字符串參數在C#

+0

你看這個類似題? https://stackoverflow.com/questions/41283289/how-do-i-map-aws-api-gateway-query-string-to-c-sharp-aws-lambda-function –

回答

0

做這樣的事情:

public string FunctionHandler(string input, ILambdaContext context); 

然後,您可以傳遞請求正文中的輸入而不是查詢字符串參數。

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

解釋超過1個輸入參數有時是也給開發商的一個問題:

步驟01:這應該是您的C-夏普方法

public string FunctionHandler(string strEnvironmentA, string strEnvironmentB, ILambdaContext context); 

步驟02:在API> GET方法執行>方法請求中添加查詢字符串參數

  • strEnvironmentA
  • strEnvironmentB

步驟03:在API> GET方法執行>合併請求>車身映射模板添加此應用程序/ JSON模板

"$input.params('strEnvironmentA')" 
"$input.params('strEnvironmentB')"