DynamoDB 可以三种格式导入数据:CSV、DynamoDB JSON 和 Amazon Ion。
CSV
CSV 格式的文件由换行符分隔的多个项目组成。默认情况下,DynamoDB 会将导入文件的第一行解释为标头,并期望列以逗号分隔。您也可以定义要应用的标头,只要它们与文件中的列数匹配即可。如果显式定义标头,则文件的第一行将作为值导入。
注意
从 CSV 文件导入时,除基表和二级索引的哈希范围和键之外的所有列都将作为 DynamoDB 字符串导入。
转义双引号
CSV 文件中存在的任何双引号字符都必须进行转义。如果未对它们进行转义(例如在以下示例中),则导入将失败:
id,value
"123",Women's Full Lenth Dress
如果使用两组双引号转义引号,则相同的导入将成功:
id,value
"""123""",Women's Full Lenth Dress
文本在经过适当转义和导入后,它将与原始 CSV 文件中的显示效果相同:
id,value
"123",Women's Full Lenth Dress
DynamoDB JSON
DynamoDB JSON 格式的文件可能包含多个 Item 对象。每个单独对象采用 DynamoDB 的标准编组 JSON 格式,换行符用作项目分隔符。作为一项附加功能,原定设置情况下,支持将时间点导出作为导入源。
注意
新行用作 DynamoDB JSON 格式的文件的项目分隔符,不应在项目对象中使用。
[{
"Item": {
"Authors": {
"SS": ["Author1", "Author2"]
},
"Dimensions": {
"S": "8.5 x 11.0 x 1.5"
},
"ISBN": {
"S": "333-3333333333"
},
"Id": {
"N": "103"
},
"InPublication": {
"BOOL": false
},
"PageCount": {
"N": "600"
},
"Price": {
"N": "2000"
},
"ProductCategory": {
"S": "Book"
},
"Title": {
"S": "Book 103 Title"
}
}
}]
注意
新行用作 DynamoDB JSON 格式的文件的项目分隔符,不应在项目对象中使用。
[{
"Item": {
"Authors": {
"SS": ["Author1", "Author2"]
},
"Dimensions": {
"S": "8.5 x 11.0 x 1.5"
},
"ISBN": {
"S": "333-3333333333"
},
"Id": {
"N": "103"
},
"InPublication": {
"BOOL": false
},
"PageCount": {
"N": "600"
},
"Price": {
"N": "2000"
},
"ProductCategory": {
"S": "Book"
},
"Title": {
"S": "Book 103 Title"
}
}
},{
"Item": {
"Authors": {
"SS": ["Author1", "Author2"]
},
"Dimensions": {
"S": "8.5 x 11.0 x 1.5"
},
"ISBN": {
"S": "444-444444444"
},
"Id": {
"N": "104"
},
"InPublication": {
"BOOL": false
},
"PageCount": {
"N": "600"
},
"Price": {
"N": "2000"
},
"ProductCategory": {
"S": "Book"
},
"Title": {
"S": "Book 104 Title"
}
}
},{
"Item": {
"Authors": {
"SS": ["Author1", "Author2"]
},
"Dimensions": {
"S": "8.5 x 11.0 x 1.5"
},
"ISBN": {
"S": "555-5555555555"
},
"Id": {
"N": "105"
},
"InPublication": {
"BOOL": false
},
"PageCount": {
"N": "600"
},
"Price": {
"N": "2000"
},
"ProductCategory": {
"S": "Book"
},
"Title": {
"S": "Book 105 Title"
}
}
}]
Amazon Ion
Amazon Ion
导入 Ion 格式的数据时,Ion 数据类型将映射到新 DynamoDB 表中的 DynamoDB 数据类型。
序列号 | Ion 到 DynamoDB 数据类型转换 | B |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ion 文件中的项目由换行符分隔。每行以 Ion 版本标记开头,后跟一个 Ion 格式的项目。
注意
在下面的示例中,为了提高可读性,我们在多行上对 Ion 格式文件中的项目进行了格式化。
$ion_1_0
[
{
Item:{
Authors:$dynamodb_SS::["Author1","Author2"],
Dimensions:"8.5 x 11.0 x 1.5",
ISBN:"333-3333333333",
Id:103.,
InPublication:false,
PageCount:6d2,
Price:2d3,
ProductCategory:"Book",
Title:"Book 103 Title"
}
},
{
Item:{
Authors:$dynamodb_SS::["Author1","Author2"],
Dimensions:"8.5 x 11.0 x 1.5",
ISBN:"444-4444444444",
Id:104.,
InPublication:false,
PageCount:6d2,
Price:2d3,
ProductCategory:"Book",
Title:"Book 104 Title"
}
},
{
Item:{
Authors:$dynamodb_SS::["Author1","Author2"],
Dimensions:"8.5 x 11.0 x 1.5",
ISBN:"555-5555555555",
Id:105.,
InPublication:false,
PageCount:6d2,
Price:2d3,
ProductCategory:"Book",
Title:"Book 105 Title"
}
}
]