Reputation: 305
I'm trying to use this Boto function, But can't seem to get it right.. Any idea? Doc Link
tablename = 'name_table'
response = dynamodb.update_item(
TableName=tablename,
Key={
'name': 'Tony',
},
UpdateExpression="set name= :r",
ExpressionAttributeValues={
':r': 'Ralph',
},
ReturnValues="UPDATED_NEW"
)
This are the errors I get :
Invalid type for parameter Key.name, value: set(['Tony', 0]), type: <type 'set'>, valid types: <type 'dict'>
I've tried to change the name from str to dict, So now I'm with this error
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Where to go from here ? Many thanks..
Upvotes: 0
Views: 121
Reputation: 8885
The keys in the API you referenced expect the values to be DynamoDB attributes, so the Key
should be like this:
{
'name': {
'S': 'Tony'
}
}
The ExpressionAttributeValues
should be like this:
{
':r': {
'S': 'Ralph'
}
}
So the whole thing looks like this:
tablename = 'name_table'
response = dynamodb.update_item(
TableName=tablename,
Key={
'name': {
'S': 'Tony'
}
},
UpdateExpression="set name= :r",
ExpressionAttributeValues={
':r': {
'S': 'Ralph'
}
},
ReturnValues="UPDATED_NEW"
)
Upvotes: 1
Reputation: 498
The key cannot be a dictionary.
tablename = 'name_table'
response = dynamodb.update_item(
TableName=tablename,
Key="name = :name",
UpdateExpression="set name= :r",
ExpressionAttributeValues={
':r': 'Ralph',
':name': 'Tony'
},
ReturnValues="UPDATED_NEW"
)
Upvotes: 0