Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

292
Views
How to set TTL in Java based app for DynamoDB

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;

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
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-how-to.html

    public void function(final AmazonDynamoDB client, final String tableName, final String ttlField){

        //table created now enabling TTL
        final UpdateTimeToLiveRequest req = new UpdateTimeToLiveRequest();
        req.setTableName(tableName);

        final TimeToLiveSpecification ttlSpec = new TimeToLiveSpecification();
        ttlSpec.setAttributeName(ttlField);
        ttlSpec.setEnabled(true);
        req.withTimeToLiveSpecification(ttlSpec);

        client.updateTimeToLive(req);
    }

about 4 years ago · Santiago Trujillo Report

0

AmazonDynamoDBClient.updateTimeToLive documented here or direct link here

about 4 years ago · Santiago Trujillo Report

0

Code Sample here.

  //Then set ttl field like below for days in java
    //ttl 60 days
    Calendar cal = Calendar.getInstance(); //current date and time      
    cal.add(Calendar.DAY_OF_MONTH, 60); //add days
    double ttl =  (cal.getTimeInMillis() / 1000L);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!