示例表和数据 - Amazon DynamoDB
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

示例表和数据

Amazon DynamoDB 开发人员指南使用示例表说明 DynamoDB 的各个方面。

表名称 主键
ProductCatalog

简单主键:

  • Id(数字)

Forum

简单主键:

  • Name(字符串)

Thread

复合主键:

  • ForumName(字符串)

  • Subject(字符串)

Reply

复合主键:

  • Id(字符串)

  • ReplyDateTime(字符串)

Reply 表具有全局二级索引 PostedBy-Message-Index。该索引方便查询 Reply 表的两个非键属性。

索引名称 主键
PostedBy-Message-Index

复合主键:

  • PostedBy(字符串)

  • Message(字符串)

有关这些表的更多信息,请参见 第 1 步:创建一个表第 2 步:使用控制台或 Amazon CLI 向表中写入数据

示例数据文件

以下章节显示了用于加载 ProductCatalogForumThreadReply 表的示例数据文件。

每个数据文件包含多个 PutRequest 元素,每个元素包含一个项目。这些 PutRequest 元素用作 BatchWriteItem 操作的输入,使用 Amazon Command Line Interface (Amazon CLI)。

有关更多信息,请参见 为 DynamoDB 中的代码示例创建表和加载数据第 2 步:使用控制台或 Amazon CLI 向表中写入数据

ProductCatalog 示例数据

{ "ProductCatalog": [ { "PutRequest": { "Item": { "Id": { "N": "101" }, "Title": { "S": "Book 101 Title" }, "ISBN": { "S": "111-1111111111" }, "Authors": { "L": [ { "S": "Author1" } ] }, "Price": { "N": "2" }, "Dimensions": { "S": "8.5 x 11.0 x 0.5" }, "PageCount": { "N": "500" }, "InPublication": { "BOOL": true }, "ProductCategory": { "S": "Book" } } } }, { "PutRequest": { "Item": { "Id": { "N": "102" }, "Title": { "S": "Book 102 Title" }, "ISBN": { "S": "222-2222222222" }, "Authors": { "L": [ { "S": "Author1" }, { "S": "Author2" } ] }, "Price": { "N": "20" }, "Dimensions": { "S": "8.5 x 11.0 x 0.8" }, "PageCount": { "N": "600" }, "InPublication": { "BOOL": true }, "ProductCategory": { "S": "Book" } } } }, { "PutRequest": { "Item": { "Id": { "N": "103" }, "Title": { "S": "Book 103 Title" }, "ISBN": { "S": "333-3333333333" }, "Authors": { "L": [ { "S": "Author1" }, { "S": "Author2" } ] }, "Price": { "N": "2000" }, "Dimensions": { "S": "8.5 x 11.0 x 1.5" }, "PageCount": { "N": "600" }, "InPublication": { "BOOL": false }, "ProductCategory": { "S": "Book" } } } }, { "PutRequest": { "Item": { "Id": { "N": "201" }, "Title": { "S": "18-Bike-201" }, "Description": { "S": "201 Description" }, "BicycleType": { "S": "Road" }, "Brand": { "S": "Mountain A" }, "Price": { "N": "100" }, "Color": { "L": [ { "S": "Red" }, { "S": "Black" } ] }, "ProductCategory": { "S": "Bicycle" } } } }, { "PutRequest": { "Item": { "Id": { "N": "202" }, "Title": { "S": "21-Bike-202" }, "Description": { "S": "202 Description" }, "BicycleType": { "S": "Road" }, "Brand": { "S": "Brand-Company A" }, "Price": { "N": "200" }, "Color": { "L": [ { "S": "Green" }, { "S": "Black" } ] }, "ProductCategory": { "S": "Bicycle" } } } }, { "PutRequest": { "Item": { "Id": { "N": "203" }, "Title": { "S": "19-Bike-203" }, "Description": { "S": "203 Description" }, "BicycleType": { "S": "Road" }, "Brand": { "S": "Brand-Company B" }, "Price": { "N": "300" }, "Color": { "L": [ { "S": "Red" }, { "S": "Green" }, { "S": "Black" } ] }, "ProductCategory": { "S": "Bicycle" } } } }, { "PutRequest": { "Item": { "Id": { "N": "204" }, "Title": { "S": "18-Bike-204" }, "Description": { "S": "204 Description" }, "BicycleType": { "S": "Mountain" }, "Brand": { "S": "Brand-Company B" }, "Price": { "N": "400" }, "Color": { "L": [ { "S": "Red" } ] }, "ProductCategory": { "S": "Bicycle" } } } }, { "PutRequest": { "Item": { "Id": { "N": "205" }, "Title": { "S": "18-Bike-204" }, "Description": { "S": "205 Description" }, "BicycleType": { "S": "Hybrid" }, "Brand": { "S": "Brand-Company C" }, "Price": { "N": "500" }, "Color": { "L": [ { "S": "Red" }, { "S": "Black" } ] }, "ProductCategory": { "S": "Bicycle" } } } } ] }

Forum 示例数据

{ "Forum": [ { "PutRequest": { "Item": { "Name": {"S":"Amazon DynamoDB"}, "Category": {"S":"Amazon Web Services"}, "Threads": {"N":"2"}, "Messages": {"N":"4"}, "Views": {"N":"1000"} } } }, { "PutRequest": { "Item": { "Name": {"S":"Amazon S3"}, "Category": {"S":"Amazon Web Services"} } } } ] }

Thread 示例数据

{ "Thread": [ { "PutRequest": { "Item": { "ForumName": { "S": "Amazon DynamoDB" }, "Subject": { "S": "DynamoDB Thread 1" }, "Message": { "S": "DynamoDB thread 1 message" }, "LastPostedBy": { "S": "User A" }, "LastPostedDateTime": { "S": "2015-09-22T19:58:22.514Z" }, "Views": { "N": "0" }, "Replies": { "N": "0" }, "Answered": { "N": "0" }, "Tags": { "L": [ { "S": "index" }, { "S": "primarykey" }, { "S": "table" } ] } } } }, { "PutRequest": { "Item": { "ForumName": { "S": "Amazon DynamoDB" }, "Subject": { "S": "DynamoDB Thread 2" }, "Message": { "S": "DynamoDB thread 2 message" }, "LastPostedBy": { "S": "User A" }, "LastPostedDateTime": { "S": "2015-09-15T19:58:22.514Z" }, "Views": { "N": "3" }, "Replies": { "N": "0" }, "Answered": { "N": "0" }, "Tags": { "L": [ { "S": "items" }, { "S": "attributes" }, { "S": "throughput" } ] } } } }, { "PutRequest": { "Item": { "ForumName": { "S": "Amazon S3" }, "Subject": { "S": "S3 Thread 1" }, "Message": { "S": "S3 thread 1 message" }, "LastPostedBy": { "S": "User A" }, "LastPostedDateTime": { "S": "2015-09-29T19:58:22.514Z" }, "Views": { "N": "0" }, "Replies": { "N": "0" }, "Answered": { "N": "0" }, "Tags": { "L": [ { "S": "largeobjects" }, { "S": "multipart upload" } ] } } } } ] }

Reply 示例数据

{ "Reply": [ { "PutRequest": { "Item": { "Id": { "S": "Amazon DynamoDB#DynamoDB Thread 1" }, "ReplyDateTime": { "S": "2015-09-15T19:58:22.947Z" }, "Message": { "S": "DynamoDB Thread 1 Reply 1 text" }, "PostedBy": { "S": "User A" } } } }, { "PutRequest": { "Item": { "Id": { "S": "Amazon DynamoDB#DynamoDB Thread 1" }, "ReplyDateTime": { "S": "2015-09-22T19:58:22.947Z" }, "Message": { "S": "DynamoDB Thread 1 Reply 2 text" }, "PostedBy": { "S": "User B" } } } }, { "PutRequest": { "Item": { "Id": { "S": "Amazon DynamoDB#DynamoDB Thread 2" }, "ReplyDateTime": { "S": "2015-09-29T19:58:22.947Z" }, "Message": { "S": "DynamoDB Thread 2 Reply 1 text" }, "PostedBy": { "S": "User A" } } } }, { "PutRequest": { "Item": { "Id": { "S": "Amazon DynamoDB#DynamoDB Thread 2" }, "ReplyDateTime": { "S": "2015-10-05T19:58:22.947Z" }, "Message": { "S": "DynamoDB Thread 2 Reply 2 text" }, "PostedBy": { "S": "User A" } } } } ] }