aws.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:donatemates 作者: donatemates 项目源码 文件源码
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.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号