Tạo bảng OrdersTable DynamoDB

Trong bước này, chúng ta sẽ tạo một bảng DynamoDB mới bằng cách sử dụng mẫu SAM.

Tạo bảng FcjOrdersTable DynamoDB

  1. Mở template.yaml trong mã nguồn bạn đã tải xuống trước đó.

    • Thêm các đoạn mã sau đây để tạo bảng FcjOrdersTable.

      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. Chạy các lệnh dưới đây.

    sam build
    sam validate
    sam deploy
    

    CreateOrderTable

  3. Mở AWS DynamoDB console để kiểm tra. CreateOrderTable