1
votes

I am trying to update an item from my DynamoDb table from a AWS Lambda function and I am getting the following error:

"errorMessage": "An error occurred (ValidationException) when calling the UpdateItem operation: The provided key element does not match the schema",

I have not defined a sort key when defining my table, and my partition key is named 'pipeId', and I have used the following code:

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('mytable')

response = table.update_item(
    Key={
        'pipeId': pipe_id
        },
    UpdateExpression="set hookId = :r",
    ExpressionAttributeValues={
            ':r': hook_id
        },
    ReturnValues="UPDATED_NEW"
)

Isn't possible to get or update an item without previously setting a sort key ? or am I doing something wrong here ?

1
I don't see anything about sort key in the error message, so not sure why you are focusing on that. It is saying that pipeId is not actually the primary key of your table. Are you sure it's not PipeID or pipe_id or something? - Mark B
I was focusing on that because I saw many other topics pointing that this error was because they were providing an incomplete key; And yes, I am using the right table name. @MarkB thank you - rickh

1 Answers

2
votes

I have found the solution.

The problem was that my primary key is defined as number and I was inserting it as String, like "3219"; but it doesn't convert automatically.