amazon-web-servicesamazon-dynamodbttl

DynamoDB TTL Problems


I have a DynamoDB table and defined a field to the expired items. In my code I carefully generated the TTL for a random 15 to 120 minutes just to test this feature, but nothing seems to happen. I waited for almost one week and the items still there. Then I saw a lot of articles and sites saying everything (including StackOverflow), but nothing seems to solve the problem. What I gathered since then:

  1. Deletion will be guaranteed, but you have to wait for 24 to 48 hours (nothing happeened)
  2. Expired items should be removed from Scans and Queries (ok)
  3. RCU and WCU should be different, so I put RCU > WCU, but nothing happens, and that's not required
  4. My items are in the table for almost one week, why?

Am I doing something wrong?

Here is the representation as Terraform Code:

resource "aws_dynamodb_table" "books_database" {
    name           = "${var.workspace}-books-database"
    billing_mode   = "PROVISIONED"
    read_capacity  = "20"
    write_capacity = "10"
    hash_key       = "Id"
    range_key      = "Title"
    stream_enabled = false

    attribute {
        name = "Id"
        type = "N"
    }

    attribute {
        name = "Title"
        type = "S"
    }

    global_secondary_index {
        hash_key        = "Title"
        name            = "TitleIndex"
        projection_type = "ALL"
        read_capacity   = 20
        write_capacity  = 10
    }

    ttl {
        attribute_name = "ExpiresAt"
        enabled        = "true"
    }
}

Example:

    Id: 47 
    Title: Ulysses 
    FirstName: James 
    LastName: Joyce 
    ExpiredAt: 1710849676
  1. Changed the RCU and WCU
  2. Waited for the deletion of the items
  3. Waited for the deletion of the items
  4. Waited for the deletion of the items
  5. Waited for the deletion of the items
  6. Waited for the deletion of the items
  7. Waited for the deletion of the items
  8. Waited for the deletion of the items

Solution

    1. Deletion will be guaranteed, but you have to wait for 24 to 48 hours (nothing happeened)

    There is no 24-48 hour guarantee, but it will be deleted if configured correctly.

    1. Expired items should be removed from Scans and Queries (ok)

    You must do this with a FilterExpression explicitly.

    1. RCU and WCU should be different, so I put RCU > WCU, but nothing happens, and that's not required

    This is not required

    1. My items are in the table for almost one week, why?

    There is no maximum time to remove the item.


    One thing you didn't do was share an example item that you expect to have been deleted already. Add that and ping me on a comment to this answer.


    You've enabled ttl in ExpiresAt but your item holds a value for ExpiredAt, those are two completely separate attribute as far as DynamoDB is concerned.