[英]Append a dictionary into a list in Dynamodb
我正在為我的 Lambda function 使用 DynamoDB 並更新我正在使用此 function 的任何項目,
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']
我想在不從服務器請求整個項目的情況下將字典 append 放入項目(列表)。 有什么辦法嗎???
這個帶有 list_apend 的修改后的 function 對我有用。
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']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.