How do I set up TTL for DynamoDB?

3 minuto de leitura
3

I want to set up time to live (TTL) for my Amazon DynamoDB table.

Short Description

To manage data lifecycles for your DynamoDB table data, use Amazon DynamoDB TTL.

Resolution

Configure TTL

To configure TTL in the DynamoDB console, complete the following steps:

  1. Open the DynamoDB console.
  2. In the navigation pane, choose Tables, and then choose the table that you want to modify.
  3. On the table details page, under Additional settings, choose Turn on for the Time To Live (TTL) setting.
  4. On the Turn on Time to Live page, for TTL attribute name, enter a unique attribute name.
    Note: The attribute name is case sensitive and must match the attribute definition in your read and write operations. For more information, see the Enable DynamoDB TTL using the AWS console section on Turn on time to live (TTL).
  5. (Optional) To run a preview of your TTL settings, enter a date and time. Then, choose Run preview. The console displays a sample list of items that you can review.

After you turn on TTL, the attribute marks items with TTL in the DynamoDB console.

Note: You can use the AWS API, AWS CLI, or AWS CloudFormation to turn on DynamoDB TTL.

Best practices for TTL

Update your TTL configuration

If you receive an error when you use TTL, then review your TTL attribute. The TTL attribute name must match an attribute for your DynamoDB table. For the TTL attribute, the data type must be a number type. For the value of the TTL attribute in your DynamoDB table, the attribute must be in epoch format at the second level of granularity.

Update multiple TTL attribute values

To use APIs to update multiple TTL attribute values, run the Scan operation. Then, run the UpdateItem call to change the TTL attribute values.

Filter by the TTL attribute

Because DynamoDB doesn't have a schema, some items in your table might not have the TTL attribute. To filter your data, run a scan operation with filter expression on the TTL attribute and with a Condition attribute "does not exist." For more information, see Filter expressions for scan.

Set an expiration time for items

It's a best practice to set an expiration time for an item when the item was last created or updated. For more information, see Computing time to live (TTL).

Related information

Working with expired items

Epoch & Unix Timestamp Conversion Tools on the EpochConverter website

Identifying deleted items in DynamoDB Streams

AWS OFICIAL
AWS OFICIALAtualizada há 3 meses
Sem comentários