user3024827
user3024827

Reputation: 1258

AWS API gateway path rather than query string

I am creating an API using AWS API Gateway and am currently using query strings to pass values into my lambda functions. This results in the URLs being structured like so:

users/user?user_id='test123'

What I would like to do is uses a path to pas in values rather than query strings. For example:

users/user/id/test123

I have looked at mapping templates and understand they are used to convert the data into the format for the function, but I am not sure how I can use a path and then map it into the lambda function.

Any ideas?

Upvotes: 1

Views: 176

Answers (1)

Lorenzo d
Lorenzo d

Reputation: 2066

You can define a resource with a variable component path like this:

/users/user/id/{userid}

Then you'd use a mapping template to pass the userid value to the Lambda function in the body of the request:

#set($inputRoot = $input.path('$'))
{
  "userId" : "$input.params('userid')"
}

Note that Lambda functions only accept parameters in the body, not query string.

Upvotes: 2

Related Questions