問題描述
您好,我需要通過 AWS Java SDK 以編程方式為 DynamoDB 中的表設置時間.是否可以?我知道最近引入了 TTL 功能 - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
Hi I need to set time to live programmatically for a table in DynamoDB via AWS Java SDK. Is it possible? I know that TTL feature is introduced recently - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
更新:沒有特別的注釋,但我們可以手動做:
UPDATE: There is no special annotaion, but we can do it manually:
@DynamoDBAttribute
private long ttl;
并在 AWS 中將其配置為 ttl - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-how-to.html
and configure it as ttl in AWS - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-how-to.html
long now = Instant.now().getEpochSecond(); // unix time
long ttl = 60 * 60 * 24; // 24 hours in sec
setTtl(ttl + now); // when object will be expired
推薦答案
AmazonDynamoDBClient.updateTimeToLive
記錄在 這里 或直接鏈接 這里
AmazonDynamoDBClient.updateTimeToLive
documented here or direct link here
這篇關于如何在基于 Java 的應用程序中為 DynamoDB 設置 TTL的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!