Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I setup an Endpoint URL with a Path Parameter within API Gateway?

I'm trying to setup an API Gateway in front of my existing setup. Whenever I try to add an endpoint with a parameter, I get an error.

Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.request.querystring.type]

Here are screenshots:

enter image description here

enter image description here

What am I doing wrong?

like image 726
Scott Foster Avatar asked Sep 09 '17 01:09

Scott Foster


2 Answers

I had the same problem too. This is what you need to do:

BTW: /number is not a part of this example

  1. Create new API resource.
  2. Go to Method Request on the Method Execution page

enter image description here

  1. Add your params under URL Query String Parameters. You can set some params to be Required as well.

enter image description here

  1. Return to the Method Execution screen (see image num 1) and now click on Integration Request

  2. Now you can see/set (in my case it was created automatically) your params under URL Query String Parameters. If not, you can define them as you see in the picture.

  3. After you finish all, click on Actions and Deploy API. You can get your Invoke URL under the Stages tab on the left menu.

enter image description here

For more information, you can see this page (AWS docs) it has good explanation about this process. Hope it helps :)

like image 108
Adi Azarya Avatar answered Oct 23 '22 01:10

Adi Azarya


In order to create a Path Parameter (which is a different concept than a query string) you create a resource with brackets, like in {your-parameter-name}.

➡️ Path Paremeter: http://example.com/products/{id}/...

A query string appends to the end of the URL like in ?value=123

The console actually gives a description tip on how to do it:

You can add path parameters using brackets. For example, the resource path {username} represents a path parameter called 'username'. Configuring /{proxy+} as a proxy resource catches all requests to its sub-resources.

Here's how to do it:

  1. Create a resource called /products

enter image description here

  1. Now create a child resource with a path text like {product}. This is the path parameter.

enter image description here

  1. Finally, add a method in which the Endpoint URL field will map the resource parameter to the target URL, which in my example is https://dummyjson.com/products/{product}. The console will help you with the suggestions and validation.

enter image description here

That's it. You can now test your API method in the console and see that everything is routed to the target endpoint, including the path parameter.

enter image description here

like image 1
Evandro Pomatti Avatar answered Oct 22 '22 23:10

Evandro Pomatti