Updating an attribute in AWS DynamoDB

0 votes

Is it not possible to add an attribute in dynamodb dynamically?

I am getting an error saying “The provided key element does not match the schema".

Scenario -

{ id : "123", imageName : "elephant.jpg" }

I want to add an attribute - imagePath : "/path/to/image" to the above data. I used put_item, but it replaces the old item if exists.

Adding an attribute can be achieved using put_item but it will replace the existing item. How can we dynamically add an attribute to the existing data using update_item?

Should I alter the schema of the table with imagePath and then use the update_item function?

Nov 2, 2018 in AWS by datageek
• 2,940 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Unfortunately, it can't be achieved in a single step. However, it can be achieved in two-step process:-

1) Try to insert the data conditionally i.e. if the key value is already present don't perform any operation (i.e. insert or update - nothing happens)

2) If there is a ConditionalCheckFailedException, then update the item

answered Nov 2, 2018 by Archana
• 5,360 points

Related Questions In AWS

0 votes
1 answer

How to add IAM role to an existing instance in aws?

As of AWS CLI v1.11.46,  you can ...READ MORE

answered Sep 6, 2018 in AWS by Archana
• 4,090 points
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

How to make an application private on AWS Elastic Beanstalk?

Like you said by default, your application ...READ MORE

answered Oct 25, 2018 in AWS by Archana
• 5,360 points
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.