How to define mulitple endpoints in one API using AWS API gateway


By default, when we create API using the AWS API Gateway service, the default resource generated is the root path “/“.
And then two steps are needed:

  1. first, create a method under the “/“ resource, for example a POST method
  2. deploy the API to a stage with any stage name you like,e.g. prod

In this case, an API endpoint will be created in this format: url/stage_name.
For example, this is one valid endpoint: “mxxggeoyvj.execute-api.us-east-1.amazonaws.com/prod”

The above steps are shown in more detail here:
Create API with API Gateway

Now, how to create multiple endpoints in the same API?

step 1, create a new resource under the “/“ resource

Clicking the “/“ path, then click “Action” and choose “create resource” as the following screenshot:

This will lead to the details of creating the child resource as our first endpoint as the following screenshot:

so this will be our first endpoint. But we need to continue to create an actual method, such as a POST method for the first endpoint like this:

Creating method is similar as before, just hook up the mehod with a lamda function, for example.

step 2, create a second resource under the “/“ resource

Clicking the “/“ path again, then click “Action” and choose “create resource” again, to create the second endpoint.
Notice that, we need to click back the “/“ path in order to create parallel endpoints under “/“ path,
such as “/endpoint1” and “/endpoint2”.

This also means, if needed, we could click the first endpoint path, and then create another resource, it will create an hierarchical path
like this “/endpoint1/endpoint2”.

After creating the second point, again, we need to create a POST method for the second endopint.

After all the above steps, the results of two parallel resources ad two endpoints are as the following:

step 3, deploy the API to stage

After we created two endopints as child resources, and each resources has a POST method, we are ready to deploy the
API to a stage, for example a stage named “prod”:


After the prod stage is deployed, we can check indvidual endpoint and its invoking url like this:

Great job done!


Author: robot learner
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source robot learner !
  TOC