How to update records in dynamo db?

0

I have updated an item in dynamodb (code sample below), so far i have updated item with attributes that already exist . if we have to add a new attribute to an exiting record, how to do it ?

also , is there a way we can update items in batch?

import boto3
db = boto3.resource("dynamodb")
table = db.Table("mytable")
def update_item():
    response = table.update_item(
        Key={"email": "abc@example.com"},
        UpdateExpression="set #name = :n",
        ExpressionAttributeNames={
            "#name": "name",
        },
        ExpressionAttributeValues={
            ":n": "John Doe",
        },
        ...
    )
asked 6 months ago505 views
1 Answer
2

Schemaless

One of DynamoDB's distinctive features is its schemaless nature, which means that unlike traditional relational databases, DynamoDB doesn't require a predefined schema for data tables. This allows developers to add or remove fields on the fly without the need for a rigid structure.

In DynamoDB, each item in a table is uniquely identified by a primary key. When making requests, especially for read and write operations, it's crucial to include the primary key attributes in order to interact with the database effectively. Any attributes which are not related to the keys can be included or not, on a per item basis.

Batch Updates

DynamoDB does not provide the ability to Batch Update, not natively. You can BatchWrite, but that overwrites data, its not an upsert. The PartiQL API allows you to use BatchExecuteStatement and can act as a work-around to allow you to do Batch Updates of items up to 25 per batch.

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchExecuteStatement.html

profile pictureAWS
EXPERT
answered 6 months 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