0

Unable to delete an item in aws dynamodb using aws-cli:

Table data in json format:

{
  "primaryKeyAttributeName": {
    "S": "2024-06-17"
  },
 "sortKeyCreatedOn": {
    "S": "2024-06-17Txx:xx:xx.xxx"
  },
  "AttributeName2": {
    "S": "CLOSED"
  },
  "AttributeName3": {
    "L": []
  },
  "lastUpdated": {
    "S": "xxxxxxx"
  },
  "lastUpdatedBy": {
    "S": "xxxx"
  }
}

As per this document https://docs.aws.amazon.com/cli/latest/reference/dynamodb/delete-item.html, tried "Example 1" as below

Command which i used for deleting an item:

aws dynamodb delete-item --table-name table-name --key file://C:/dao/key.json --return-values ALL_OLD --return-consumed-capacity TOTAL --return-item-collection-metrics SIZE `  

File contents of C:/dao/key.json:

{
    "primaryKeyAttributeName": {"S": "2024-06-17"},
    "AttributeName2": {"S": "CLOSED"}
}

Am expecting to delete, but receiving this error:

An error occurred (ValidationException) when calling the DeleteItem operation: The provided key element does not match the schema

if i use this command its working and able to display the item:

aws dynamodb query --table-name tableName --key-condition-expression "primaryKeyAttributeName = :v1" --expression-attribute-values
file://C:/dao/expression-attributes.json --return-consumed-capacity TOTAL

File contents of C:/dao/expression-attributes.json:

{
    ":v1": {"S": "2024-06-17"}
}

if i use this command its not working and receiving the same exception:

aws dynamodb get-item --table-name tableName --key file://C:/dao/key.json --return-consumed-capacity TOTAL

File contents of C:/dao/key.json:

{
    "primaryKeyAttributeName": {"S": "2024-06-17"}
}
4
  • 1
    Can you share the collection schema definition - the partition and sort keys? Commented Jun 20, 2024 at 0:55
  • What is your sort key? Commented Jun 20, 2024 at 5:03
  • 1
    Does this answer your question? What is the recommended way to delete a large number of items from DynamoDB? Commented Jun 20, 2024 at 13:14
  • You have to use the full Primary Key (PK + SK) to delete an item in DDB Commented Jun 20, 2024 at 13:14

1 Answer 1

1

If your table has both a primary key and a sort key, then you need to provide both in the --key parameter. So your C:/dao/key.json JSON file needs to look like this:

{
    "primaryKeyAttributeName": {"S": "2024-06-17"},
    "sortKeyCreatedOn": {"S": "2024-06-17Txx:xx:xx.xxx"}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.