def update_attribute(self, key_dict, attribute_name, attribute_value):
"""Method to update a single attribute in a record
Args:
key_dict (dict): A dictionary containing the keys/values to query on. Supports simple and compound keys
attribute_name (str):
attribute_value (str):
Returns:
None
"""
response = self.table.update_item(Key=key_dict,
UpdateExpression="SET {} = :updated".format(attribute_name),
ExpressionAttributeValues={':updated': '{}'.format(attribute_value)})
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise Exception("Error getting item: {}".format(response['ResponseMetadata']))
# TODO: Check if any sort of validation on a update should done. DynamoDB seems lax here.
#if "Attributes" in response:
# if len(response["Attributes"]) == 0:
# raise ValueError("Specified key does not exist. Update failed.")
#else:
# raise ValueError("Specified key does not exist. Update failed.")
评论列表
文章目录