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

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Can I have create table syntax as I find datamapper more suited for CrUD. Thanks
based on this answer, only scalar type can be defined. if so, will accept this answer. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.