AWS API Gateway with Lambda: add "Get By ID" definition

This thing is not trivial and I didn't found any simple explanation about this. So that is 
  • select an existing resource (eg. "users")

  • click on "Actions" dropdown and select "Create Resource"

  • in "Resource Name" put parameter name in curly braces (eg. {userid})

  • in "Resource Path" you should see read-only text "/users/" and textbox for parameter
  • write {userid} in this textbox and click "Create Resource"
  • you should see a new branch in your API tree - /{userid}. Select it.

  • click "Create Resource"-"Create Method" and add ANY method there


  • integrate it with Lambda function you alrteady used for ANY of this resource (don't forget check "Use Lambda Proxy integration")

  • select this new brand ANY method, go to "Method Request" and ensure that there is "userid" parameter in "Request Paths" section


That is it. Now you should handle it in your Lambda (to support both QS and Path params):

    var params = event.pathParameters? event.pathParameters : event.queryStringParameters;

Use params.userid to get a value.




Comments

Popular posts from this blog