Как мы можем вставить следующие данные в историю aws dynamodb.Как разместить json-массив в AWS dynamodb
{
"userId":"4",
"gpId": "44",
"uname": "username",
"position":"Cloud Solution Engineer",
"companyName" : "xyz Technlologies",
"skills": [{"linux":"1","windows":"2","Docker": "3"}]
}
Я попытался, используя следующий код в node.js
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)"
]
}
Я попытался карту применения, как это предлагается в ответ, но это дает мне следующую ошибку:
{
"errorMessage": "There were 3 validation errors:\n* UnexpectedParameter: Unexpected key 'linux' found in params.Item['skills'].M['0']\n* UnexpectedParameter: Unexpected key 'windows' found in params.Item['skills'].M['0']\n* UnexpectedParameter: Unexpected key 'Docker' found in params.Item['skills'].M['0']",
"errorType": "MultipleValidationErrors",
"stackTrace": [
"* UnexpectedParameter: Unexpected key 'linux' found in params.Item['skills'].M['0']",
"* UnexpectedParameter: Unexpected key 'windows' found in params.Item['skills'].M['0']",
"* UnexpectedParameter: Unexpected key 'Docker' found in params.Item['skills'].M['0']",
"ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:40:28)",
"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)",
"callNextListener (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:95:12)",
"/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:75:9",
"finish (/var/runtime/node_modules/aws-sdk/lib/config.js:308:7)",
"/var/runtime/node_modules/aws-sdk/lib/config.js:324:9",
"EnvironmentCredentials.get (/var/runtime/node_modules/aws-sdk/lib/credentials.js:126:7)",
"getAsyncCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:318:24)",
"Config.getCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:338:9)"
]
}
https://www.npmjs.com/package/dynamodb-data-types, проверить это –