我们如何将以下数据插入到aws dynamodb故事中。
*
我尝试在node.js中使用以下代码
{
"userId":"4",
"gpId": "44",
"uname": "username",
"position":"Cloud Solution Engineer",
"companyName" : "xyz Technlologies",
"skills": [{"linux":"1","windows":"2","Docker": "3"}]
}
我正在尝试以下代码,它向我提供以下错误。
var userId=event.userId;
var gpId=event.gpId;
var fbId=event.fbId;
var uname=event.uname;
var position=event.position;
var role=event.role;
var companyName=event.companyName;
var skills=event.skills;
dynamodb.putItem({
"TableName": tableName,
"Item" : {
"userId": {"N": userId},
"gpId": {"N": gpId},
"uname" : {"S":uname},
"position" : {"S":position},
"role" : {"S":role},
"companyName" : {"S":companyName},
"skills" : {"SS":skills}
}
我尝试使用{
"errorMessage": "Expected params.Item['skills'].S to be a string",
"errorType": "InvalidParameterType",
"stackTrace": [
"ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)",
"ParamValidator.validateType (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:218:10)",
"ParamValidator.validateString (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:150:14)",
"ParamValidator.validateScalar (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:130:21)",
"ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:94:21)",
"ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)",
"ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)",
"ParamValidator.validateMap (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:117:14)",
"ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:92:21)",
"ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)"
]
}
更改{"S": skills}
。
它给了我以下错误:
skills
我已尝试按照回答中的建议应用地图,但它给了我以下错误:
{
"errorMessage": "Unexpected key '0' found in params.Item['skills']",
"errorType": "UnexpectedParameter",
"stackTrace": [
"ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)",
"ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:77:14)",
"ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)",
"ParamValidator.validateMap (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:117:14)",
"ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:92:21)",
"ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)",
"ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)",
"ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)",
"Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:109:42)",
"Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)"
]
}
答案 0 :(得分:0)
skills
不是字符串集( SS ),在以下0索引赋值后,它应该具有Map属性类型( M ):< / p>
var skills = event.skills[0];
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html