1

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.