1
votes

The table in DynamoDB looks as below:

partition_key, created_at

I intend to delete items based on created_at - when the data is too old, then delete it. I tried the following command:

aws dynamodb delete-item --table-name my_table --condition-expression "created_at <= 1479655145317"

But it complains aws: error: argument --key is required, I intend to delete the item not based on partition key, any suggestions? Thanks.

2

2 Answers

1
votes

Partition key is must to delete the item from DynamoDB. There is no workaround to delete the item without providing the partition key.

In the above case, you need two step process.

1) Scan or query (if you have GSI on created_at) to get the partition key that needs to be deleted

2) Use delete item api to delete the item based on partition key

1
votes

Somewhat related: Time To Live (TTL) for DynamoDB allows you to define when items in a table expire so that they can be automatically deleted from the database. http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html