Create DynamoDB Table

Overview

In this step, you will create a DynamoDB Table to store invoice information after it is processed by the Lambda function. The table will use on-demand mode and have 2 additional Global Secondary Indexes (GSIs) to support queries by customer name and starred invoices.


Step 1: Access DynamoDB Console

  1. Log in to AWS Console, search for DynamoDB, then select DynamoDB in the results.

Open DynamoDB

💡 Note: Before clicking Create table, make sure you have selected the correct region as US East (N. Virginia) (us-east-1) in the upper right corner of the AWS Console screen.

  1. Click Create table to start creating a new table.

Create Table


Step 2: Configure DynamoDB table

  1. Table name: InvoiceData

  2. Partition key:

  • Name: InvoiceId
  • Type: String
  1. Skip the Sort key section (not necessary).

Table Key

  1. In the Table settings section, Select Default settings to switch to On-demand capacity mode.

Billing Mode

  1. Click Create table to finish.

Create Table


Step 3: Add Global Secondary Index (GSI)

Once the InvoiceData table is successfully created, you will add two secondary indexes:


GSI #1: CustomerName-index
  1. In the table details page, select the Indexes tab.

Create Index

  1. Click Create index.

Create Index

  1. Configuration:
  • Partition key: CustomerName
  • Data type: String
  • Sort key: (leave blank)
  • Projected attributes: select All

GSI 1

GSI 1

  1. Click Create index.

GSI 1


GSI #2: StarredInvoicesIndex
  1. Click Create index again to create the second GSI.

GSI 2

  1. Configuration:
  • Partition key: IsStarred (type String)
  • Sort key: CreatedAt (type String)
  • Index name: StarredInvoicesIndex
  • Projected attributes: select All

GSI 2

GSI 2

  1. Click Create index.

GSI 2

  1. Make sure both GSIs CustomerName-index and StarredInvoicesIndex are in ACTIVE status before continuing with Lambda function configuration.

Check GSI Status

⚠️ If the GSI status is still Creating, you need to wait a few minutes until it changes to Active before making a query or deploying a Lambda to access the GSI.