Tee*_*Kay 1 python amazon-dynamodb aws-lambda validationexception
我正在尝试更新 DynamoDB 表中的项目。我编写的代码正在更新该项目,但是当我添加标题为“源/目标”的列时,它给出了“ValidationException”异常。
用于更新的代码 -
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table("test")
response = table.update_item(
Key={
'id': "test_id
},
UpdateExpression="set source/target= :st, user_name= :usr",
ExpressionAttributeValues={
':st' : event['source/target'],
':usr' : event['user_name']
},
ReturnValues="UPDATED_NEW"
)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是 -
调用UpdateItem操作时发生错误(ValidationException):Invalid UpdateExpression:语法错误;标记:\"/\",附近:\"源/目标\""
怎么解决这个问题呢?
您好,当您有任何特殊字符时,您必须使用 ExpressionAttributeNames,如下所示
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table("test")
response = table.update_item(
Key={
'id': "test_id"
},
UpdateExpression="set #colName= :st, user_name= :usr",
ExpressionAttributeValues={
':st' : event['source/target'],
':usr' : event['user_name']
},
ExpressionAttributeNames={
'#colName' : 'source/target'
},
ReturnValues="UPDATED_NEW"
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5789 次 |
| 最近记录: |