Create OrdersTable DynamoDB table

In this step, we will create a new DynamoDB table using a SAM template.

Create FcjOrdersTable DynamoDB table

  1. Open template.yaml in the source code you downloaded before.

    • Add the following scripts below to create FcjOrdersTable table.

      orderTable:
        Type: String
        Default: OrdersTable
      

      CreateOrderTable

      FcjOrdersTable:
        Type: AWS::DynamoDB::Table
        Properties:
          TableName: !Ref orderTable
          BillingMode: PAY_PER_REQUEST
          AttributeDefinitions:
            - AttributeName: id
              AttributeType: S
            - AttributeName: book_id
              AttributeType: S
          KeySchema:
            - AttributeName: id
              KeyType: HASH
            - AttributeName: book_id
              KeyType: RANGE
      

      CreateOrderTable

  2. Run the below commands.

    sam build
    sam validate
    sam deploy
    

    CreateOrderTable

  3. Open AWS DynamoDB console to check. CreateOrderTable