Mở console DynamoDB, chọn Create table.
Chat-Messages.ConversationId (String).Timestamp (Number). Tin nhắn trong một cuộc trò chuyện được sắp theo thời gian.
Bảng thứ hai cần một global secondary index để tìm các cuộc trò chuyện của một người. Tạo bảng này trong CloudShell:
aws dynamodb create-table --table-name Chat-Conversations \
--attribute-definitions AttributeName=ConversationId,AttributeType=S AttributeName=Username,AttributeType=S \
--key-schema AttributeName=ConversationId,KeyType=HASH AttributeName=Username,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST \
--global-secondary-indexes 'IndexName=Username-ConversationId-index,KeySchema=[{AttributeName=Username,KeyType=HASH},{AttributeName=ConversationId,KeyType=RANGE}],Projection={ProjectionType=ALL}' \
--query 'TableDescription.[TableName,TableStatus,GlobalSecondaryIndexes[0].IndexName]' --output text
Chat-Conversations với khóa ConversationId + Username.Username-ConversationId-index đảo thứ tự khóa. Code Lambda gọi index theo đúng tên này.