I have a nodejs app and I am using putItem() to insert into DynamoDB. The table that I am passing the value to has a primary key called "id". Now what I am trying to do is to generate a UUID and set the primary key value to that UUID whenever I insert the data. However when I insert, the "id" is inserted with double quotes. For eg: instead of id: 229f0a06-7257-4727-b825-a6e8ea343b1e it will show as id : "229f0a06-7257-4727-b825-a6e8ea343b1e". I checked the schema and it shows that "id" KeyType is HASH. This is the code I have to insert into DB:
let data = {};
data.id= uuidv4(); //Trying to set the primary key "id"
data.name = "Test";
const dynamoDB = new DynamoDBClient;
const result = await dynamoDB.putItem(data);
When I go check in the DB table, it shows id : "229f0a06-7257-4727-b825-a6e8ea343b1e". How can I set the "id" so that it doesn't show up with double-quotes?
Thanks.
How can I set the "id" so that it doesn't show up with double-quotes?
You don't want to. Your Partition Key (= Hash Key) data type is String, which of course is the right data type for UUIDs.
Hash Key is a DynamoDB synonym for Partition Key. As such, HASH in the CreateTable KeySchema API is not a data type, but rather is a reference to the Partition Key field. The docs continue, "the attributes in KeySchema must also be defined in the AttributeDefinitions", to a data type to one of (S)tring, (N)umber or (B)inary.