def increment_attribute(self, key_dict, attribute_name, increment_value):
"""Method to increment 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): The attribute to increment
increment_value (int): The amount to increment the attribute by
Returns:
None
"""
response = self.table.update_item(Key=key_dict,
UpdateExpression="SET {} = {} + :increment".format(attribute_name,
attribute_name),
ExpressionAttributeValues={':increment': increment_value},
ReturnValues="UPDATED_NEW")
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise Exception("Error getting item: {}".format(response['ResponseMetadata']))
评论列表
文章目录