Create OrdersTable DynamoDB table

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

Create FCAJOrdersTable DynamoDB table

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

    • Add the following parameter to define the table name for FCAJOrdersTable.

      orderTable:
        Type: String
        Default: OrdersTable
      

      Add orderTable parameter

    • Add the following resource block to create the FCAJOrdersTable DynamoDB table.

      FCAJOrdersTable:
        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
      

      Add FCAJOrdersTable resource

  2. Run the below commands to validate and build the SAM template.

    sam validate
    sam build
    

    SAM validate and build

  3. Deploy the updated stack.

    sam deploy
    

    SAM deploy with FCAJOrdersTable

  4. Wait for the CloudFormation stack to finish creating the FCAJOrdersTable resource.

    CloudFormation FCAJOrdersTable CREATE_COMPLETE

  5. Open AWS DynamoDB console to verify the OrdersTable has been created successfully.

    DynamoDB Tables with OrdersTable