Amazon dynamodb 如何添加/更新DynamoDB条目,创建或附加到列表属性?

Amazon dynamodb 如何添加/更新DynamoDB条目,创建或附加到列表属性?,amazon-dynamodb,Amazon Dynamodb,这是我的用例,我需要在DynamoDB表中添加和更新条目,如下所示: response = ddb_client.update_item( TableName=target_ddb_table, Key={'email-hash': {'S' : encrypted_hashed_pw},}, ExpressionAttributeValues={ ":my_value":[{"S":"test"}], ":empty_list":[] }, UpdateExpr

这是我的用例,我需要在DynamoDB表中添加和更新条目,如下所示:

response = ddb_client.update_item(
    TableName=target_ddb_table,
    Key={'email-hash': {'S' : encrypted_hashed_pw},},
    ExpressionAttributeValues={ ":my_value":[{"S":"test"}], ":empty_list":[] },
    UpdateExpression='SET site_ids = list_append(if_not_exists(site_ids, :empty_list), :my_value)',
    ReturnValues='ALL_NEW'
)
如果分区键不存在,添加它并添加一个新的包含字符串值的单元素列表。 如果分区键确实存在,请向其列表属性添加新字符串。 我有一段代码,Python/boto3如下所示:

response = ddb_client.update_item(
    TableName=target_ddb_table,
    Key={'email-hash': {'S' : encrypted_hashed_pw},},
    ExpressionAttributeValues={ ":my_value":[{"S":"test"}], ":empty_list":[] },
    UpdateExpression='SET site_ids = list_append(if_not_exists(site_ids, :empty_list), :my_value)',
    ReturnValues='ALL_NEW'
)
我犯了这些错误,我意识到我在做一些愚蠢的事情:re

Invalid type for parameter ExpressionAttributeValues.:empty_list, value: [], type: <class 'list'>, valid types: <class 'dict'>
Invalid type for parameter ExpressionAttributeValues.:my_value, value: [{'S': 'test'}], type: <class 'list'>, valid types: <class 'dict'>
参数表达式属性值的类型无效:空列表,值:[],类型:,有效类型:
参数expressionAttributeValue的类型无效:my_值,值:[{'S':'test'}],类型:,有效类型:

想好了,我需要为列表添加类型信息:

":my_value": {"L": [{"S": "test"}]}, ":empty_list": {"L": []}