Part 1 - API Gateway

The first step of your journey is to deploy API Gateway as it will make all future cutovers transparent to the end-users. Initially, the API Gateway is used as a proxy for the legacy APIs. As you continue to strangle out the monolith in future labs, you will configure the API Gateway to route requests to the new microservices.

Create API

  1. In the AWS Management Console, navigate to API Gateway.

    Navigating to API Gateway Console

  2. Start creating a new REST API by clicking the “Build” button in the “REST API” box. (You will also see another box with title “REST API Private”, DON’T choose that since we want a public API.)

    API Gateway Build REST API Button

  3. In the next view, configure your API Gateway using the settings below. Then click “Create API”.

    • Choose the protocol: Select “REST”

    • Create new API: Select “New API”

    • API name: Enter Unishop

    • Description: Enter An API for the Unishop

    • Endpoint Type: Select “Regional”

    API Gateway Create New API Display

Create Resources

When you first create a REST API, there are no resources (URLs) or methods (GET/POST/PUT/etc) created for it. API Gateway allows you to have different resources (URLs or paths) and methods assigned to different back-end APIs. For this lab, however, you will configure the API to proxy all requests to the same back-end URL - the Elastic Beanstalk URL - using the proxy resource and ANY method pattern.

API Gateway Empty API

  1. In the center pane, in the “Actions” dropdown, select “Create Resource”.

    API Gateway Create api Resource Button

  2. For “Resource Name”, enter api. Doing so, will also autofill the “Resource Path”. Tick the “Enable API Gateway CORS” box and then click the “Create Resource” button.

    API Gateway api Resource

  3. You will then add a child resource to the “api” resource. On the left side “Resources” menu select the newly created resource “/api”. From the “Actions” menu, click “Create Resource.”

    API Gateway Create proxy Resource

  4. Check the “Configure as proxy resource” box to configure the new resource as a proxy resource. This will automatically populate the resource name and path (see screenshot below). Once again, tick the “Enable API Gateway CORS” box. Click “Create Resource.”

    API Gateway proxy Resource

Create Method

You will now configure the ANY method pattern under the “/{proxy+}” resource.

  1. By default, the ANY method should have been created under the “/{proxy+}” resource. Click “ANY”. In the method setup on the right, configure the following:

    • Integration type: Select “HTTP Proxy”

    • Endpoint URL: Enter the value of “Elastic Beanstalk LegacyApplication URL” in your cheat sheet and append api/{proxy} to the end. (If you forget to copy this value to your cheat sheet, please refer to this step.)

    • Content Handling: Select “Passthrough”

    Here is a SAMPLE Endpoint URL:{proxy}. Note that you should find YOUR OWN in the Elastic Beanstalk Console. If you forgot to note down your own Elastic Beanstalk Endpoint URL, please refer to the part 3 of Environment Setup.

    API Gateway Create Method

  2. Click the “Save” button to save your changes. You will now see the following:

    API Gateway ANY Method Setup

  3. On the resources left side menu, select the “/{proxy+}” resource. From the “Actions” menu, click “Enable CORS.”

    API Gateway ANY Method Setup

  4. Here you will add a header. In the “Access-Control-Allow-Headers” field, delete the entire default content, and replace it with the text below. Once you’re done, click “Enable CORS and replace existing CORS headers.”


    API Gateway ANY Method Setup

  5. Confirm your changes by clicking the “Yes, replace existing values” button.

    API Gateway Test Link

  6. Click the “ANY” method under “/{proxy+}”. The content pane will show a graphical-like view of the full round-trip path of requests, starting with the client in a box on the left, and the back-end resource in a box on the right. In the client box there is a “Test” link. Click that link.

    API Gateway Test Link

  7. In the method test view, select “GET” as the method and enter unicorn as the path. Then, click the “Test” button. The response body (right side of the pane) should show the JSON representation of all the unicorns.

    API Gateway Test Preresult

    API Gateway Test Result

  8. Finally, you will deploy the API. In the center pane, click the “Actions” dropdown and click “Deploy API.”

    API Gateway Deploy

  9. In the Deploy API dialog window that appears, select “[New Stage]” in the Deployment stage dropdown and enter prod as the stage name. Then click “Deploy”.

    API Gateway Deploy Settings

  10. You can test the REST API proxy by clicking on the “Invoke URL” link and then appending /api/unicorn to the URL in your browser. You will again see an XML or JSON serialization of the unicorns. Please note down this “Invoke URL” in your cheat sheet (You should paste it under “API Gateway Invoke URL”). If you are ready, let’s move on!

    API Gateway Invoke

    Both API Gateway and S3 (used in the part 2) allow you to use your own domain name. For example, you might use and for API Gateway and S3 respectively. You can read more about configuring API Gateway and S3 to use custom domain names in the documentation.