DynamoDB table attributes are deleting when executing a put_item from a Lambda Python

0

I have a situation where all attributes in a table are being deleted except for the PK and the attribute I did put against. After Python Lambda executes a put all attributes except for the OK and attributes I did put against are elevated.

For example (all strings):

  • ID //the PK
  • AttrA
  • AttrB
  • AttrC

I perform the following put: Resp = table.put_item( Item={ 'ID': '1', 'AttrA': accta (a local Python string var) } )

Resp shows a positive return of 200, and a transaction occurred.

When I go to the DynamoDB console and look at the table, AttrB and AttrC have been deleted.

Should I be using a table.update_item instead?

profile picture
Petrus
asked 14 days ago491 views
1 Answer
1

Yes, the behavior you're seeing is expected when using put_item in DynamoDB. The put_item operation in DynamoDB creates a new item or replaces an existing item with the same primary key. This means that any attributes that are not included in the put_item request will be deleted. [1] Source

💡 If you want to update specific attributes of an existing item without affecting the other attributes, you should use the update_item operation instead. [2] source

profile picture
EXPERT
answered 14 days ago
profile pictureAWS
EXPERT
reviewed 14 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions