How to Create an API Gateway Using the AWS Console

By John Paul Mueller

You can create a simple API by using one of the Amazon examples. The idea is to help you get started using APIs with a minimum of fuss so that you can see the API workflow. Later examples will help you create custom APIs so that you can see all the ways in which you can modify API behavior. The following steps get you started.

  1. Sign into AWS by using your user account.
  2. Navigate to the API Gateway Console.

    AWS displays a welcome message and displays a Get Started button (unless you created an API Gateway previously).

  3. Choose an API Gateway setup region from the Region drop-down list at the top of the page.

    The example uses the Oregon region.

  4. Click Get Started.

    AWS displays a message about creating an example API. The example produces a Pet Store API using Swagger, which is a popular application for producing APIs. You can create your APIs by using Swagger and import them directly into AWS.

  5. Click OK.

    Notice that you can

    • Create a new API using just the console functionality.
    • Import a new API that you created using Swagger.
    • Run the example API to see how API Gateway works.

      This example uses the third option, Example API. You can see the JSON code used to create the example API below the three options. The options regarding warnings help you ensure that the API you import will actually work with Amazon. In most cases, you want to enable Fail On Warnings to ensure that you don’t import an invalid API description.

      new API AWS
      You have a number of options for creating a new API on AWS.
  6. Choose Example API; choose Fail on Warnings; then click Import.

    You see the Resources view. The Navigation pane on the left shows you the kinds of information that is available. In the middle is a hierarchical view of the API. The right pane shows a detail view of the selected resource. The API is only imported at this point. You can perform all sorts of additional tasks, such as creating new methods and resources. You can also view the details of a particular element, such as a method.

    resources after you import API
    The example shows a hierarchical view of the resources after you import the API.
  7. Click POST in the Resource Tree.
    You see the POST method execution. Note that the conversation begins with the client. Each of the little bull’s-eye dots is a hint. You can click them to get additional information about that element. You can also click the major headings, such as Method Request, to learn more about that element and configure it as part of working with the API. To test the API, you click TEST (with the lightning bolt) in the Client element, as described in the next step.
    Resource Tree elements
    Detail views show how various Resource Tree elements work.
  8. Click TEST in the Client element.

    You see the display. This page shows all the potential elements required to make a test as well as which ones you actually require. For example, you don’t need any headers, stage variables, or client certificates. However, this example does require a Request Body entry to work properly.

    test with required inputs AWS
    Performing a test means providing required inputs.
  9. Type the following code in the Request Body field:

    {"type": "cat", "price": 50.00}

    The JSON request asks for a pet of type cat at a price of $50.00.

  10. Click Test.

    You see output.Note that you see the default headers with a status of 200 (showing a successful request). The response body contains the original request and a message value of success. The response headers show the kind of information you can expect from this kind of request. Finally, you see a series of log entries that tell you precisely how the request and response process proceeded. Now that you know the API works, you can deploy it.

    visualize how API will work
    The testing process helps you visualize how the API will work.
  11. Select the forward slash (/) entry in the Resource Tree.

    To deploy an API, you must select the root node of the Resource Tree.

  12. Choose Actions → Deploy API.

    You see a Deploy API dialog box. You must describe the level of deployment so that everyone working on the project will know the API’s status.

    deploy API AWS
    After testing, you can deploy your API.
  13. Choose [New Stage] in the Deployment Stage field.
  14. Type TestDeploy in the State Name field.

    You may optionally include a stage and deployment description, but they aren’t required for the example.

  15. Click Deploy.

    You see the detail information about the deployment. The information for your deployment will vary from the information you see here. Note especially the Invoke URL field near the top. The example is now ready to work with.

    API configuration settings
    The deployed API is ready for use, but you can still change some configuration settings.

It’s time to see whether the API actually works. Open a new browser window. Using the Invoke URL field entry as a starting point, add a question mark and then a name/value pair. In this case, you ask for all the cat entries.

GET Method
Use the GET method to ask for all the cat entries.

You can also see a specific entry. All you need is the ID value added to the URL to see a specific entry. The output appears here.

obtain specifi entry
Provide an ID to obtain a specific entry.

To test the POST method easily, you need a third-party product such as Postman.