Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put Items using Json File in AWS DynamoDB using AWS CLI

While putting below JSON in dynamo DB using AWS CLI with below command:

aws dynamodb put-item --table-name ScreenList --item file://tableName.json

I am getting Parameter validation failed Exception.I have gone rigorously through AWS docs but failed to find example to insert a complicated json.Every small help is welcome.

The updated Json :

{
  "itemName": {
    "S": "SCREEN_LIST"
  },
  "productName": {
    "S": "P2P_MOBITEL"
  },
  "screenList": {
    "L": [
      {
        "menu": {
          "L": [
            {
              "M": {
                "menuId": {
                  "N": "1"
                },
                "menuText": {
                  "S": "ENG_HEADING"
                },
                "menuType": {
                  "S": "Dynamic"
                }
              }
            }
          ]
        },
        "M": {
          "screenFooter": {
            "S": "F_LANGUAGE_CHANGE"
          },
          "screenHeader": {
            "S": "H_LANGUAGE_CHANGE"
          },
          "screenId": {
            "S": "LANGUAGE_CHANGE"
          },
          "screenType": {
            "S": ""
          }
        }
      }
    ]
  }
}
like image 637
Priancy Avatar asked Aug 03 '17 10:08

Priancy


1 Answers

It seems that you are defining complex types incorrectly. According to AWS documentation you should define a list like this:

"L": ["Cookies", "Coffee", 3.14159]

and a map should be defined like this:

"M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}

which means that a menu map should be defined like this:

"menu": { 
  "L": [
    {
      "M": {
        "menuId": {"N" :"1"},
        "menuText": {"S" :"PACKS_SCREEN"},
        "menuType": {"S" :"Dynamic"}
      }
    }
  ]
}

Notice the "M" and "L" attributes.

You should change the rest of your JSON in a similar fashion.

You can find full JSON definition here in the Options section.

UPDATE

Now your list definition is incorrect. You have:

   "screenList":{  
      "L":[  
         {  
            "menu":{ ... },
            "M":{ ... }
         }
      ]
   }

While it should be:

   "screenList":{  
      "L":[  
         {  
            "M":{ ... }   
         },
         {  
            "M":{ ... }   
         },
      ]
   }
like image 131
Ivan Mushketyk Avatar answered Sep 21 '22 01:09

Ivan Mushketyk