Create API Gateway (GET)

Tổng quan

This section guides you through creating a REST API named GetInvoiceAPI with routes for querying and updating invoice data. Each route is connected to a Lambda function and has CORS enabled, then deployed with a dev stage.


Step 1: Create REST API

  1. Sign in to the AWS Management Console, search for and open API Gateway.

Open API Gateway

  1. Click Create an API.

Create API

  1. Select REST API, then click Build.

Build REST API

  1. Configure the following:

    • API name: GetInvoiceAPI
    • Description: Post Invoice File by API Gateway
    • Endpoint Type: Select Regional.

API Details

  1. Click Create API to finish.

Create API


Step 2: Create Resources & Methods

Resource: /invoice
  1. In GetInvoiceAPI, choose Create resource.

Create resource

  1. Enter:

    • Resource path: /
    • Resource name: invoice
  2. Click Create resource.

Create resource

  1. After creating /invoice, select it in the resource tree.

resource /invoice

  1. Click Create method.

Create method

  1. Configure in Create method:

    • Method type: GET.
    • Integration type: Lambda function.
    • Lambda proxy integration: Enabled.
    • Lambda function: FetchInvoiceDetailsFunction.

Configuration

Configuration

  1. Click Create method.

Create method

  1. The API Gateway will be created and redirected to the API Gateway details configuration page.

Configuration details

Resource: /invoice/{id}
  1. In the resource tree, select the /invoice resource.

resource /invoice

  1. In the resource tree, select the /invoice resource.

Create resource

  1. Enter the following:

    • Resource path: /invoice/
    • Resource name: {id}
  2. Click Create resource.

Create resource

  1. After the /invoice/{id} resource is created, select it again in the resource tree.

Resource /invoice/{id}

  1. Click Create method.

Create method

  1. Configure the Create method section:

    • Method type: GET.
    • Integration type: Lambda function.
    • Lambda proxy integration: Enabled.
    • Lambda function: FetchInvoiceDetailsFunction.

Configuration

Configuration

  1. Click Create method.

Create method

  1. Proceed to add a PATCH method.

    • Select the resource in the tree and click Create method again.

Choose resource & click create method

- Configure similarly:

    - **Method type**: PATCH
    - **Integration type**: Lambda Function
    - **Use Lambda Proxy integration**: Enabled
    - **Lambda Function**: FetchInvoiceDetailsFunction

Configuration

  1. Click Create method.

Create method

Resource: /invoice/starred
  1. In the GetInvoiceAPI, select the /invoice resource.

resource /invoice

  1. Click Create resource.

Create resource

  1. Configure:

    • Resource path: /invoice/
    • Resource name: starred
  2. Click Create resource.

Configuration & Create resource

  1. After the resource is created, select /invoice/starred in the tree.

Resource /invoice/starred

  1. Click Create method.

Create method

  1. Configure the Create method:

    • Method type: GET.
    • Integration type: Lambda function.
    • Lambda proxy integration: Enabled.
    • Lambda function: FetchInvoiceDetailsFunction.

Configuration

  1. Click Create method.

Create method

Resource: /invoice/starred/{id}
  1. In GetInvoiceAPI, select /invoice/starred.

Resource /invoice/starred

  1. Click Create resource.

Create resource

  1. Configure:

    • Resource path: /invoice/starred/
    • Resource name: {id}
  2. Click Create resource.

Configuration & Create resource

  1. After the resource is created, select /invoice/starred/{id}.
  2. Click Create method.

Create method

  1. Configure the Create method:

    • Method type: PATCH.
    • Integration type: Lambda function.
    • Lambda proxy integration: Enabled.
    • Lambda function: FetchInvoiceDetailsFunction.

Configuration

  1. Click Create method.

Create method

Resource: /invoice/tags
  1. In GetInvoiceAPI, select /invoice.

Resource /invoice

  1. Click Create resource.

Create resource

  1. Configure:

    • Resource path: /invoice/
    • Resource name: tags
  2. Click Create resource.

Configuration & Create resource

Resource: /invoice/tags/{id}
  1. In the resource tree, select /invoice/tags.
  2. Click Create resource.

Create resource

  1. Configure:

    • Resource path: /invoice/tags/
    • Resource name: {id}
  2. Click Create resource.

Configuration & Create resource

  1. After the resource is created, select /invoice/tags/{id}.
  2. Click Create method.

Create method

  1. Configure the Create method:

    • Method type: PATCH.
    • Integration type: Lambda function.
    • Lambda proxy integration: Enabled.
    • Lambda function: FetchInvoiceDetailsFunction.

Configuration

  1. Click Create method.

Create method

Step 3: Enable CORS for methods

  1. In the resource tree of GetInvoiceAPI, select /invoice/{id}.
  2. Click Enable CORS.

Enable CORS

  1. In Access-Control-Allow-Methods, Enabled CORS:

    • GET
    • PATCH
  2. Click Save.

Save CORS

  1. Repeat the above steps for the following resources:

    • /invoice/starred/{id}: Enabled CORS for PATCH
    • /invoice/tags/{id}: Enabled CORS for PATCH

Result

Result

Step 4: Deploy API

  1. Click Deploy API.

Deploy API

  1. In the Deploy API modal:

    • Stage: [New Stage].
    • Stage name: dev.
    • Deployment description: Test API Method GET.
    • Click Deploy.

New stage

Configuration