Setting and Enable CORS

In this section, we will add binary file support settings and enable CORS for the APIs.

Configure Binary Media Types

  1. Select API Settings from the left menu, then click Manage media types APISettings

  2. On Manage binary media types page:

    • Click Add binary media type
    • Enter multipart/form-data
    • Click Save changes BinaryMediaTypes

Enable CORS for /books Resource

  1. Go back to Resources from the left menu:

    • Select /books resource
    • Click Enable CORS EnableCORS
  2. On Enable CORS page:

    • Select GET and POST methods
    • Click Save EnableCORS

Enable CORS for /{id} Resource

  1. Select /{id} resource and click Enable CORS EnableCORS

  2. On Enable CORS page:

    • Select DELETE method
    • Click Save EnableCORS

Deploy API

  1. To allow front-end to use the APIs, we need to deploy them:

    • Select / resource
    • Click Deploy API DeployAPI
  2. On Deploy API popup:

    • Select New stage from dropdown DeployAPI
  3. Enter stage name, e.g., staging, then click Deploy DeployAPI

  4. Note the Invoke URL to call APIs InvokeURL

  5. URL for List and Write APIs (GET/POST /books): BooksURL

  6. URL for Delete API (DELETE /books/{id}): DeleteURL

So we have finished configuring API Gateway with GET, POST, DELETE methods and enabled CORS.