I created a table on DynamoDB with partition key Robot (Number) ans sort key Status (string). I have written this code to update the Status of two items in a given condition through this code
import boto3
from boto3.dynamodb.conditions import Key
TABLE_NAME = "RobotStatus"
# Creating the DynamoDB Client
dynamodb_client = boto3.client('dynamodb', region_name="eu-central-1")
# Creating the DynamoDB Table Resource
dynamodb=boto3.resource('dynamodb', region_name="eu-central-1")
table=dynamodb.Table(TABLE_NAME)
# Use the DynamoDB client query method to get robot1's status
response=dynamodb_client.query(
TableName=TABLE_NAME,
KeyConditionExpression='Robot = :Robot',
ExpressionAttributeValues={
':Robot': {'N': "1"}
}
)
if response['Items'][0]['Status']['S'] == "disconnected":
response=table.update_item(
Key={'Robot': "2"},
UpdateExpression = "set #st = :s",
ExpressionAttributeValues={":s" : "disconnecting"},
ExpressionAttributeNames={"#st":"Status"},
ReturnValues="UPDATED_NEW"
)
response=table.update_item(
Key={'Robot': "3"},
UpdateExpression="set #st = :s",
ExpressionAttributeValues = {":s" : "disconnecting"},
ExpressionAttributeNames={"#st":"Status"},
ReturnValues="UPDATED_NEW"
)
but once I run the script this error pops up
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the UpdateItem operation: The provided key element does not match the schema
I have also tried to add the sort key inside the Key field of UpdateItem but nothing changes, do you know what could be the problem?