本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
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 格式的檔案可以包含多個項目物件。每個個別物件都是 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 格式時,DynamoDB 資料表中使用的 DynamoDB 資料類型會映射至 Ion 資料類型。
S. 編號 | 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"
}
}
]