I am trying to make a DynamoDB table with several attributes and only one primary key,Some of the attributes are SS,NS type.However when create table with all these attributes, there was an error that attribute should be in [N,S,B]. So i researched an found that we only need to define the attribute type of primary key and add data later.My table got created but I have no idea how to add data with new ids and these attributes.Can somebody help me? I need to insert data in DynamoDB with all other attributes with following types. This is my code with which I created table:
Code:
var AWS = require("aws-sdk");
AWS.config.update({
region: "us-west-2",
endpoint: "http://localhost:3000"
});
var dynamodb = new AWS.DynamoDB();
var params = {
TableName : "USERS",
KeySchema: [
{ AttributeName: "UserID", KeyType: "HASH"}
],
AttributeDefinitions: [
{ AttributeName: "UserID", AttributeType: "N" },
// { AttributeName: "Name", AttributeType: "S" },
//{ AttributeName: "Preference", AttributeType: "SS" }
// { AttributeName: "Profile_picture", AttributeType: "B" },
//{ AttributeName: "Rating", AttributeType: "N" },
//{ AttributeName: "User_available", AttributeType: "N" },
//{ AttributeName: "Tasks", AttributeType: "NS" },
//{ AttributeName: "Room_Interested", AttributeType: "NS" }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
};
dynamodb.createTable(params, function(err, data) {
if (err) {
console.log("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
}
});
via user3930213
No comments:
Post a Comment