将字典附加到 Dynamodb 中的列表中

Append a dictionary into a list in Dynamodb

我正在为我的 Lambda 函数使用 DynamoDB 并更新我正在使用此函数的任何项目,

def update_title(title, val, dynamodb=None):
    if not dynamodb:
        dynamodb = boto3.resource('dynamodb')

    table = dynamodb.Table('variable')

    try:
        response = table.update_item(
        Key={'var_name': title},
        UpdateExpression="set var_value=:p",
        ExpressionAttributeValues={':p': val},
        ReturnValues="UPDATED_NEW"
        )
    except ClientError as e:
        print(e.response['Error']['Message'])
    else:
        return response['Attributes']

我想将字典附加到项目(列表)中,而不需要从服务器请求整个项目。有什么办法吗???

这个带有 list_apend 的修改后的函数对我有用。

def update_list_title(title, val, dynamodb=None):
if not dynamodb:
    dynamodb = boto3.resource('dynamodb')

table = dynamodb.Table('coindcx_variable')

try:
    response = table.update_item(
    Key={'var_name': title},
    UpdateExpression="set var_value=list_append(var_value, :p)",
    ExpressionAttributeValues={':p': val},
    ReturnValues="UPDATED_NEW"
    )
except ClientError as e:
    print(e.response['Error']['Message'])
else:
    return response['Attributes']