简体   繁体   中英

AWS Lambda parameter passing

I am creating an api with AWS API Gateway with Lambda functions. I want to be able to make an API call with the following criteria:

  • In the method request of the API i have specified the Query String: itemid
  • I want to be able to use this itemid value within my lambda function
  • I am using Python in Lambda

I have tried putting the following in the Mapping template under the Method execution, however get an error:

-{ "itemid": "$input.params('itemid')" }

您还必须在“资源/方法请求”部分中包括查询字符串参数。

I would use the proxy integration in API Gateway, this way your Lambda function receives the entire request. Take a look at the docs to set it up. When configured as a proxy, the input to your Lambda function will look something like this:

{  
   "path":"/test/hello",
   "headers":{  
      "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
      "Accept-Encoding":"gzip, deflate, lzma, sdch, br",
      "Accept-Language":"en-US,en;q=0.8",
      "CloudFront-Forwarded-Proto":"https",
      "CloudFront-Is-Desktop-Viewer":"true",
      "CloudFront-Is-Mobile-Viewer":"false",
      "CloudFront-Is-SmartTV-Viewer":"false",
      "CloudFront-Is-Tablet-Viewer":"false",
      "CloudFront-Viewer-Country":"US",
      "Host":"wt6mne2s9k.execute-api.us-west-2.amazonaws.com",
      "Upgrade-Insecure-Requests":"1",
      "User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48",
      "Via":"1.1 fb7cca60f0ecd82ce07790c9c5eef16c.cloudfront.net (CloudFront)",
      "X-Amz-Cf-Id":"nBsWBOrSHMgnaROZJK1wGCZ9PcRcSpq_oSXZNQwQ10OTZL4cimZo3g==",
      "X-Forwarded-For":"192.168.100.1, 192.168.1.1",
      "X-Forwarded-Port":"443",
      "X-Forwarded-Proto":"https"
   },
   "pathParameters":{  
      "proxy":"hello"
   },
   "requestContext":{  
      "accountId":"123456789012",
      "resourceId":"us4z18",
      "stage":"test",
      "requestId":"41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9",
      "identity":{  
         "cognitoIdentityPoolId":"",
         "accountId":"",
         "cognitoIdentityId":"",
         "caller":"",
         "apiKey":"",
         "sourceIp":"192.168.100.1",
         "cognitoAuthenticationType":"",
         "cognitoAuthenticationProvider":"",
         "userArn":"",
         "userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48",
         "user":""
      },
      "resourcePath":"/{proxy+}",
      "httpMethod":"GET",
      "apiId":"wt6mne2s9k"
   },
   "resource":"/{proxy+}",
   "httpMethod":"POST",
   "body": "...",
   "queryStringParameters":{  
      "name":"me"
   },
   "stageVariables":{  
      "stageVarName":"stageVarValue"
   }
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM