connect-dynamodb icon indicating copy to clipboard operation
connect-dynamodb copied to clipboard

TTL not set up on table creation

Open pablocompagni-contractorvp opened this issue 3 years ago • 2 comments

The library currently creates the DynamoDB table if it doesn't exists. In that process it doesn't seem to be properly setting the table TTL to the expires attribute of the sessions. Is there any reason for this?

I believe you need to set a TTL on the table yourself and set the TTL value to reside in the expires field of the record

camin-mccluskey avatar Mar 12 '22 15:03 camin-mccluskey

Are there any plans to add TTL? I have a few thoughts on this:

  • It would be much simpler if we could pass the TTL field to the CreateTableCommand. Unfortunately it has to be applied after creation with UpdateTimeToLiveCommand.
  • CreateTableCommand returns immediately with a TableStatus of CREATING. I assume that has to be ACTIVE before the TTL can be added.
  • In lib/connect-dynamodb.js I see that DynamoDBStore.prototype.initialize() calls describeSessionsTable() if the table has not been initialized. DescribeTableCommand doesn't provide TTL info, but that might be a good time to also call DescribeTimeToLiveCommand and perform UpdateTimeToLiveCommand.
  • It seems like an always-on single server won't run initialize after table creation is complete, but if this is running serverlessly or on multiple instances that this will eventually happen.
  • DynamoDB uses the epoch in seconds, not milliseconds, for TTL. I saw some discussion that this is being migrated, and I see a reference to "oneDayInMilliseconds" for the default expires value, but this issue seems to assume that it is a valid DDB TTL. Does that need to be modified (as a breaking change) as well?

mschersten avatar Sep 26 '23 13:09 mschersten