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:
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.
If you need more strict deletion, you may have to create your own implementation of the feature.