Error InvalidParameterType: Expected params.Item['pid'] to be a structure in DynamoDB

后端 未结 2 1276
猫巷女王i
猫巷女王i 2021-01-01 09:50

Note: all these are happening on the local instance of DynamoDB.

This is the code that I\'ve used to create a table from the DynamoDB Shell:

var para         


        
2条回答
  •  Happy的楠姐
    2021-01-01 10:12

    The putItem() method on the AWS.DynamoDB class is expecting the params.Item object to be formatted as a AttributeValue representation. That means you would have to change this:

    params = {
      TableName: 'TABLE-NAME',
      Item: {
        pid: 'abc123'
      }
    };
    

    Into this:

    params = {
      TableName: 'TABLE-NAME',
      Item: {
        pid: {
          S: 'abc123'
        }
      }
    };
    

    If you want to use native javascript objects you should use the AWS.DynamoDB.DocumentClient class, that automatically marshals Javascript types onto DynamoDB AttributeValues like this:

    • String -> S
    • Number -> N
    • Boolean -> BOOL
    • null -> NULL
    • Array -> L
    • Object -> M
    • Buffer, File, Blob, ArrayBuffer, DataView, and JavaScript typed arrays -> B

    It provides a put() method, that delegates to AWS.DynamoDB.putItem().

提交回复
热议问题