Search code examples
amazon-dynamodbamazon-ion

Import items to DynamoDB from S3, what is the correct ion format?


I want to import many items to DynamoDB from a ion file, there is an example of importing only one item in official document. But how to import many items at once ? I have tried:

$ion_1_0{
  Item: [
    {
      pk:1d0,
      sk:1d0,
      c1: "sql",
    },
    {
      pk:1d0,
      sk:2d0,
      c1: "mono",
    }
  ]
}
$ion_1_0{
  Item: {
    pk:1d0,
    sk:1d0,
    c1: "sql",
  },
  Item: {
    pk:1d0,
    sk:2d0,
    c1: "mono",
  }
}

All failed.

The document give an multi-items example in json format, but it is even not a valid json.

And i don not want to use BatchWriteItem api, because it's much more expensive than import from S3.

Please give me a correct example of importing many items to DynamoDB from one ion/json file.


Solution

  • From AWS doc:-

    Items in an Ion file are delimited by newlines. Each line begins with an Ion version marker, followed by an item in Ion format.

    Here is the working example:-

    $ion_1_0 {Item:{pk:2.,sk:2.,c1:"mono"}}
    $ion_1_0 {Item:{pk:1.,sk:1.,c1:"sql"}}
    

    In case of import failure, you can always check in Cloudwatch logs for the exact error message.

    Hope this helps.