0

My question is similar to the one asked for java but need help with javascript aws-sdk. Couldn't find any examples.

the table structure would be as shown below:

customer:
  customerId: '12345'
  policies:
  - policyNumber: 12345
    status: active
patb23
  • 387
  • 5
  • 21

1 Answers1

0

You can try using DocumentClient.put() see documentation. Below is a sample from my existing code updated to match your payload but I haven't tested it since I didn't want to pollute my table.

   import AWS from 'aws-sdk';

   const params = {
      TableName: 'TBL_CUSTOMER', //or whatever your table name is
      Item: {
         customerId: '12345',
         policies: {
            policyNumber: 12345,
            status: 'active'
         }
      }
   };

   const documentClient = new AWS.DynamoDB.DocumentClient();

   const result = await new Promise((resolve, reject) => {
      documentClient.put(params, function (err, data) {
         if (err) reject(err);
         else resolve(data);
      });
   });
   console.log('result:', result);
Adi H
  • 668
  • 7
  • 9
  • Can I have create table syntax as I find [datamapper](https://www.npmjs.com/package/@aws/dynamodb-data-mapper) more suited for CrUD. Thanks – patb23 Apr 13 '20 at 05:48
  • based on [this answer](https://stackoverflow.com/a/55080737/889474), only scalar type can be defined. if so, will accept this answer. Thanks – patb23 Apr 13 '20 at 07:16