DynamoDB Time to Live (TTL) not working, despite it is active

349 views Asked by At

UPDATE: Ok, it "kind works", it took more than ~10 minutes to call the lambda. For anyone who is reading this question I do not recommend using this feature (TTL & Stream), it is so broken, they say that it may take 48 hours in big tables, but my table has a single element.


It seems like the Time to Live (TTL) feature of DynamoDB is not working. Even in a table with only one item, I've been waiting for hours, but the item still remains in the database even after it should have expired.

This is my CloudFormation template. I basically copied it from the official documentation.

DynamoDBTable:
  Type: AWS::DynamoDB::Table
  Properties:
    BillingMode: PAY_PER_REQUEST
    AttributeDefinitions:
      - AttributeName: id
        AttributeType: S
      # - AttributeName: ttl
      #   AttributeType: N
    KeySchema:
      - AttributeName: id
        KeyType: HASH
      # - AttributeName: ttl
      #   KeyType: RANGE
    TimeToLiveSpecification:
      AttributeName: ttl
      Enabled: true
    StreamSpecification:
      StreamViewType: NEW_AND_OLD_IMAGES

No matter the TTL value, whether it's set in the past or the future, the document is never deleted. I've checked multiple times, and the TTL option is active.

I also use a stream for a Lambda, and the "REMOVE" events only come through if I manually delete, which indicates that the stream is functioning.

Images as reference:

enter image description here

enter image description here

enter image description here

1

There are 1 answers

11
Leeroy Hannigan On

DynamoDB TTL does not delete items immediately when the expiration date expires. It can in some cases take several days, whereas you have only been waiting for hours.

TTL typically deletes expired items within a few days. Depending on the size and activity level of a table, the actual delete operation of an expired item can vary. Because TTL is meant to be a background process, the nature of the capacity used to expire and delete items via TTL is variable (but free of charge).

If you need more strict deletion, you may have to create your own implementation of the feature.