首页 > 解决方案 > python boto3 dynamodb 查询函数动态参数

问题描述

Python boto3 库 dynamodb.query 方法。我们如何传递动态参数

client = boto3.resource("dynamodb")

params = {
    "Limit": 10,
    "ExpressionAttributeNames":{"#pk":"pk"},
    "ExpressionAttributeValues":{":pk":"value"},
    "KeyConditionExpression":"#pk=:pk",
    "ScanIndexForward": False
}
res = client.query(params)

它以错误响应:

An error occurred (ValidationException) when calling the Query operation: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.

标签: pythonamazon-dynamodbboto3

解决方案


尝试使用 ** 正确设置参数:

res = client.query(**params)

推荐阅读