0
votes

I want to import json file into dynamoDB via AWS cli.

I have created a demo table music with partition key name.

I entered below command :

aws dynamodb put-item --table-name music --item file://0001.json --return-consumed-capacity TOTAL

I receive following error:

Parameter validation failed: Invalid type for parameter Item.Count, value: 503, type: , valid types: Invalid type for parameter Item.Items, value: [OrderedDict([('phoneNumber', OrderedDict([('S', 'GpDxxZRJIlUuoqlULj6h0w==')])),

below is my json file, is there anything wrong with the:

{
  "Items": [
    {
      "phoneNumber": {
        "S": "GpDxxZRJIlUuoqlULj6h0w=="
      },
      "isfisheye": {
        "N": "0"
      },
      "isdeleted": {
        "N": "0"
      },
      "contactFEId": {
        "S": "FE160959275516"
      },
      "ismerged": {
        "N": "0"
      },
      "source": {
        "S": "fromPhone"
      },
      "secondaryPhoneNumbers": {
        "L": [
          {
            "S": "n/a"
          }
        ]
      },
      "email": {
        "S": "XVRb5DlaaC8yIfujKnLsUkV+yv0Ry9nPeWN2iv9OQPY="
      },
      "name": {
        "S": "Sankey Vaishali"
      },
      "isBlocked": {
        "N": "0"
      },
      "contactId": {
        "S": "1528891536"
      },
      "sharedData": {
        "N": "2"
      },
      "secondaryEmails": {
        "L": [
          {
            "S": "n/a"
          }
        ]
      },
      "userId": {
        "S": "FE1411544738781"
      },
      "privacyEnabled": {
        "N": "1"
      }
    },
  ],
  "ScannedCount": 503
}

I have a doubt that may be the json format might be wrong. Can anyone help to solve this as i'm new to aws.

1
I have tried all the way, also tried to insert records through command line, it works but if i import file it gives an error. - Prathamesh Doke
What is inside filename.json? - shuvalov
@shuvalov i have updated my question, its 0001.json contains json data. - Prathamesh Doke
If i tried to insert record manually, it works and it shows in cli -> { "ConsumedCapacity": { "TableName": "music", "CapacityUnits": 1.0 } } , but when i tried it with json file. it shows the same data in prettyprint format in the console. - Prathamesh Doke

1 Answers

1
votes

Your JSON looks like the output of get-item command. Your requests failed due to wrong format - all objects must be tagger with internal DynamoDB tags as described here. You should remove Items and ScanndedCount from the JSON as follows:

{
    "contactFEId": {
        "S": "FE160959275516"
    },
    "contactId": {
        "S": "1528891536"
    },
    "email": {
        "S": "XVRb5DlaaC8yIfujKnLsUkV+yv0Ry9nPeWN2iv9OQPY="
    },
    "isBlocked": {
        "N": "0"
    },
    "isdeleted": {
        "N": "0"
    },
    "isfisheye": {
        "N": "0"
    },
    "ismerged": {
        "N": "0"
    },
    "name": {
        "S": "Sankey Vaishali"
    },
    "phoneNumber": {
        "S": "GpDxxZRJIlUuoqlULj6h0w=="
    },
    "privacyEnabled": {
        "N": "1"
    },
    "secondaryEmails": {
        "L": [
            {
                "S": "n/a"
            }
        ]
    },
    "secondaryPhoneNumbers": {
        "L": [
            {
                "S": "n/a"
            }
        ]
    },
    "sharedData": {
        "N": "2"
    },
    "source": {
        "S": "fromPhone"
    },
    "userId": {
        "S": "FE1411544738781"
    }
}