Skip to content

Commit 38ed206

Browse files
Enable TTL on DynamoDB table creation
This commit adds TTL enablement to the DynamoDB store setup process. Previously, TTL values were stored in items but the table-level TTL feature was never enabled, meaning expired items would never be automatically deleted by DynamoDB. Changes: - Added update_time_to_live call in _setup() method - Enabled TTL on the 'ttl' attribute after table creation - Added error handling for ValidationException (already enabled case) This addresses one of the critical issues identified in #168 for marking DynamoDB store as stable. Batch operations implementation is deferred to a future PR. Co-authored-by: William Easton <[email protected]>
1 parent 23f4a9c commit 38ed206

File tree

1 file changed

+14
-0
lines changed
  • key-value/key-value-aio/src/key_value/aio/stores/dynamodb

1 file changed

+14
-0
lines changed

key-value/key-value-aio/src/key_value/aio/stores/dynamodb/store.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ async def _setup(self) -> None:
164164
waiter = self._connected_client.get_waiter("table_exists") # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
165165
await waiter.wait(TableName=self._table_name) # pyright: ignore[reportUnknownMemberType]
166166

167+
# Enable TTL on the table
168+
try:
169+
await self._connected_client.update_time_to_live( # pyright: ignore[reportUnknownMemberType]
170+
TableName=self._table_name,
171+
TimeToLiveSpecification={
172+
"Enabled": True,
173+
"AttributeName": "ttl",
174+
},
175+
)
176+
except self._connected_client.exceptions.ClientError as e: # pyright: ignore[reportUnknownMemberType]
177+
# TTL may already be enabled, check error code
178+
if e.response["Error"]["Code"] != "ValidationException": # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType]
179+
raise
180+
167181
@override
168182
async def _get_managed_entry(self, *, key: str, collection: str) -> ManagedEntry | None:
169183
"""Retrieve a managed entry from DynamoDB."""

0 commit comments

Comments
 (0)