Here is an example of how to update an item in DynamoDB using Boto3:
import boto3
# Initialize a session using Amazon DynamoDB
dynamodb = boto3.resource('dynamodb')
# Select your table
table = dynamodb.Table('YourTableName')
# Update an item in the table
response = table.update_item(
Key={
'PrimaryKeyAttribute': 'Value1',
'SortKeyAttribute': 'Value2' # Only if you have a composite primary key
},
UpdateExpression="set Attribute1 = :val1",
ExpressionAttributeValues={
':val1': 'NewValue'
},
ReturnValues="UPDATED_NEW"
)
print("UpdateItem succeeded:")
print(response)