AWS DynamoDB snippets
How to update data of a DynamoDB table with Python boto3
Please note that this snippet is part of the DynamoDB-Simpsons-episodes-full-example repository on GitHub.
Let's say you want to update an item of the DynamoDB simpsonsEpisodes
table.
table = dynamodbRes.Table(TABLENAME)
response = table.update_item(
Key={
'No_Season': 99,
'No_Inseason' : 1
},
UpdateExpression='SET Title = :newTitle',
ExpressionAttributeValues={
':newTitle': 'Worst episode ever!'
},
ReturnValues="UPDATED_NEW"
)
print(response)
{'Attributes': {'Title': 'Worst episode ever!'},
'ResponseMetadata': {'RequestId': 'MOUB7GEBMHP84TIC5FVMQBK8D3VV4KQNSO5AEMVJF66Q9ASUAAJG',
'HTTPStatusCode': 200,
'HTTPHeaders': {'server': 'Server',
'date': 'Wed, 07 Dec 2022 16:23:17 GMT',
'content-type': 'application/x-amz-json-1.0',
'content-length': '52',
'connection': 'keep-alive',
'x-amzn-requestid': 'MOUB7GEBMHP84TIC5FVMQBK8D3VV4KQNSO5AEMVJF66Q9ASUAAJG',
'x-amz-crc32': '1885714143'},
'RetryAttempts': 0}}