I have a dynamoDB table with the key name as id and a String field called state. I just want to update the value of the state using update_item DynamoDb Python client.
DDB_CLIENT.update_item(
Key={
'id' : {'S': id}
},
TableName='TrackingState',
UpdateExpression="set state = :r",
ExpressionAttributeValues={
':r': '"state": {"S": "IN_PROGRESS"}'
}
)
I get an error: Invalid type for parameter ExpressionAttributeValues type: <class 'str'>, valid types: <class 'dict'>
If I try expressionAttributeValues as:
':r' : {"state": {"S": "IN_PROGRESS"}} I get the error: Unknown parameter in ExpressionAttributeValues.:r: "state", must be one of: S, N, B, SS, NS, BS, M, L, NULL, BOOL
If I try
':r' : {"S": "QUEUED"}
Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: state
What is the right way to update an entry in DynamoDb table
If I try
':r' : {"S": "QUEUED"} Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: state
That's right, the state keyword could not be used in expression, so the ExpressionAttributeNames dict permits to use it.
DDB_CLIENT.update_item(
Key={
'id' : {'S': id}
},
TableName='TrackingState',
UpdateExpression="set #s = :r",
ExpressionAttributeNames={
'#s': "state"
},
ExpressionAttributeValues={
':r': {"S": "QUEUED"}
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With