Create API Gateway (POST)

Tổng quan

In this section, you will create a REST API Gateway to receive invoices uploaded by users through the POST /uploads endpoint. This API will integrate with Lambda Function #1 UploadInvoiceFileFunction, automatically process invoice images/files using AI, and store the results into DynamoDB.


Step 1: Create a REST API

  1. Log in to the AWS Management Console, find and access API Gateway.

Open API Gateway

  1. Click Create API.

Create API

  1. Choose REST API type, then click Build.

Build REST API

  1. In the configuration section:

    • API name: PostInvoiceAPI
    • Description: Post Upload Invoice File by API Gateway
    • Endpoint Type: Select Regional.
  2. Click Create API to finish.

Create API


Step 2: Create Resource

Resource: /uploads
  1. In PostInvoiceAPI, select Create resource.

Create resource

  1. Enter information:

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

Create resource

Step 3: Create Method

Method: POST
  1. In the resource tree, select /uploads.

  2. Click Create method.

Create method

  1. Configure in Create method:

    • Method type: POST.
    • Integration type: Lambda function.
    • Lambda proxy integration: Enabled.
    • Lambda function: UploadInvoiceFileFunction.

Configuration

  1. Click Create method.

Create method

Method: PUT
  1. In the resource tree, select /uploads.

  2. Click Create method.

Create method

  1. Configure in Create method:

    • Method type: PUT.
    • Integration type: Lambda function.
    • Lambda proxy integration: Enabled.
    • Lambda function: UploadInvoiceFileFunction.

Configuration

  1. Click Create method.

Create method

Step 4: Enable CORS for methods

  1. In the resource tree of PostInvoiceAPI, select resource /uploads.
  2. Click Enable CORS.

Enable CORS

  1. In Access-Control-Allow-Methods, enable CORS for:

    • POST
    • PUT
  2. Click Save.

Save CORS

Step 5: Deploy the API

  1. Click Deploy API.

Deploy API

  1. In the Deploy API modal:

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

New stage

Configuration