Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API GateWay can't have multiple paths?

I just got my custom domain name setup via AWS API Gateway, and now I have several domain names all routing to one lambda function. which just serves a webpage.

The setup looks like this:

enter image description here

And I have several of these with different domains that I want all to serve the same content.

Now, I'd like to add another path like /getdata or something which will just serve some data from a database instead of serving static HTML.

But when I try to add another path I get this error:

Error Only one base path mapping is allowed if the base path is empty.

How can I have a single domain with multiple paths then?

I tried just using the wildcard path: *, and that works for multiple paths like /test or /getdata, but it doesn't work with just the domain name, and I can't tell every single user to make sure to type something in like /home everytime

like image 420
frogengine773 Avatar asked Aug 28 '18 20:08

frogengine773


People also ask

What are the limitations of AWS API gateway?

No quota up to the total account quota. 10 requests per second with a burst quota of 40 requests per second. To use the Amazon Web Services Documentation, Javascript must be enabled.

What is API gateway base path mapping?

Connects a custom domain name registered via aws. apigateway. DomainName with a deployed API so that its methods can be called via the custom domain name.

How many requests can AWS API gateway handle?

Amazon API Gateway has raised the default limit on requests made to your API to 10,000 requests per second (RPS) from 1,000 RPS. The burst limit has been raised to 5,000 requests across all APIs in your account from the original limit of 2,000 requests.

What is API gateway resource path?

API Gateway defines a proxy resource as a placeholder for a resource to be specified when the request is submitted. A proxy resource is expressed by a special path parameter of {proxy+} , often referred to as a greedy path parameter. The + sign indicates whichever child resources are appended to it.


2 Answers

Ahh I figured it out!

So, unfortunately, the page that shows you the custom domains is not where you need to be making your routes.

The correct procedure is to create an API (or use an existing API, and modify the resources) and give it a proxy resource, and a plain GET method that originates from the root path.

First, go to your API GateWay console, and create a new API.

Then once you give it a name, and choose the type (regional, or edge), it will show you the resources page

Here, you will do 2 things: Create a catch all proxy resource, and also a get resource to the root path.

Step 1: Make a catch all proxy resource:

enter image description here

Click Actions, and choose Create Resource

On the wizard, click Configure as proxy, and give it a name. Leave the resource path as it is. Then click create resource. The {proxy+} is notation that tells AWS that this resource should accept any path that has anything after the /. This means /test will work as well as /test/1/2/3/etc. However just / alone will not work!

enter image description here

Next, it will take you to this screen where you choose your integration type. We want lambda, which is the default. Make sure to select the correct region, for me the default was the right one. Then start typing in your lambda function name, and it should dynamically pop up a list of your lambda functions. select the one that you want for your application. If that doesn't work, you can copy and paste your lambda ARN from the lambda function console. Click Save.

Step 2: Make a get resource for the root path

enter image description here

Click the root slash at the top, right under where it says resources. Then click actions, and choose Create Method. It will pop up a little selection thing under the root slash, and there you should select GET, and then click the little checkmark.

enter image description here

Here, make sure to check Use Lambda Proxy Integration, and then the rest of this form should be the same as the last one you did. Just select your region, and your lambda function, and click Save.

Step 3: Deploy

Once that's done, go to actions, and choose Deploy API, give it a name for a stage, and some description, and then you are ready to attach this API to your custom domain.

Step 4: Attach

On the left tab scroll down to where it says Custom Domain Names, and create a new domain name (or attach it to an existing one if you have it)

Enter your domain name, and choose regional or edge. Then choose your certificate (there are many good guides for how to make a certificate through AWS)

Once you click save, it will look something like this:

enter image description here

Click Show Base Path Mappings, and then Edit.

enter image description here

In the path field just leave a slash, in the Destination field, choose from the dropdown the API that you just deployed. And on the right, select the stage that you made when you deployed your API.

Lastly, it will sit at initializing for a while, so while you wait for that, remember that you need to make a route53 record set for this domain, and map it to the cloudfront target URL that the API GateWay gave us. This target url looks like: www.u10dsa3s5iovdk.cloudfront.net. Copy that, and go to Route 53, Choose the hosted zone for your domain. Create a record set, and give it the same name as the domain you just created, so if you made www.example.com, in the name field of Route 53 you need to type in www. or if you made test.example.com you need to type in test. Then choose Alias: Yes, and for the Alias Target, paste in the cloudfront url from API GateWay.

When the custom domain name is done initializing, you can make calls to www.example.com as well as www.example.com/anything/else/you/want/to/put/here

Hope this helps anyone who was stuck as long as I was. Please let me know if there's anything I missed, or if something is inaccurate.

like image 76
frogengine773 Avatar answered Nov 06 '22 06:11

frogengine773


In this case you need to configure a path different to "/" for each api you need to serve through custom domain. AWS Api Gateway don't let you to serve several api into the same custom domain if you serve at least one api with no base path.

like image 27
Yunier Saborit Ramírez Avatar answered Nov 06 '22 05:11

Yunier Saborit Ramírez